3
votes

Since we use a lot of @ApplicationScoped beans with transaction but we do not want to use EJBs (ApplicationScoped bean does not work with stateless beans), we create our own transaction interceptor such as:

@Resource
UserTransaction tx; 
@Resource(mappedName="java:jboss/TransactionSynchronizationRegistry")
TransactionSynchronizationRegistry tsr;

@AroundInvoke
public Object manageTransaction(InvocationContext context) throws Exception {
    Object result;
    if (Status.STATUS_NO_TRANSACTION == tsr.getTransactionStatus()) {
        tx.begin();
        // System.out.println("Starting transaction");
        result = context.proceed();
        tx.commit();
    } else {
        result = context.proceed();
    }
    // System.out.println("Committing transaction");

    return result;
}

However, in the case of JTA transaction, we got errors such as:

Using own TransactionInterceptor caused
Caused by: java.sql.SQLException: java.sql.SQLException: XAER_RMFAIL: The command cannot be executed when global transaction is in the IDLE state

We used to use Seam3 managed transaction and it seems working fine. But it does not work in Wildfly anymore. We tried Deltaspike's jpa module, but it seems having problems with transaction around multiple datasources (non-JTA seems fine) even we followed their instruction.

We also tried @Applicationscoped @TransactionalManagement but it does not give us transaction.

What are my options in using Wildfly but not @Stateful or @Statelss @Singleton, etc?

1

1 Answers

1
votes

Have you tried javax.transaction.Transactional (new in Java EE 7)?

@ApplicationScoped
@Transactional
public MyTransactionalBean {
    // ...
}