I have a @Stateless
EJB using container managed transaction. Is there a way to access the "status" of javax.transaction.UserTransaction
? That is, calling UserTransaction.getStatus()
inside the bean methods?
I know access to UserTransaction
is prohibited in container managed beans, but I would like to know, is there any other way to get access to getStatus()
method?
If you only need to know if the transaction is marked for rollback, then use EJBContext.getRollbackOnly. Otherwise, with JTA 1.1, you can use TransactionSynchronizationRegistry:
TransactionSynchronizationRegistry tsr = (TransactionSynchronizationRegistry)
new InitialContext().lookup("java:comp/TransactionSynchronizationRegistry");
int status = tsr.getTransactionStatus()