What happens to a bean managed JTA transaction at timeout?

Latest response

According to the documentation it is marked for rollback, but if I'm managing that transaction, and it times out or we reboot the server it is associated with a thread indefinitely. Then we get this exception:

Caused by: java.lang.IllegalStateException: BaseTransaction.checkTransactionState - ARJUNA016051: thread is already associated with a transaction!

Basically the transaction lives on that thread and is orphaned. How should I deal with this situation? We never had this issue on JBoss 4, but now that we've upgraded to JBoss EAP 6.2.3 we're experiencing the exception.

Responses

Hi

Please take a look at the Knowledge Base Article here: https://access.redhat.com/solutions/497823. I think this article answers your questions.

Thanks
Mustafa

Our service layer is not structured like the article. Our servlet has no reference to an actual EJB, and we don't have any code that nests transactions. A request comes in, our service starts the transaction, executes the database code and commits or rolls back the transaction. The service is a POJO that basically has this in it:

InitialContext initialContext = new InitialContext();
UserTransaction userTransaction = (UserTransaction) initialContext.lookup("java:jboss/UserTransaction");

try {

    userTransaction.begin();

    // Do some stuff...
    // Whoops, it took too long to do stuff and the transaction timed out... but what happened to it?

    userTransaction.commit();

} catch(Exception exception) {

    userTransaction.rollback();

}

Now another request comes in, is given the same thread, and executes the same logic. However, it goes to begin the transaction, and the one that timed out is still associated with that thread. It's very basic transaction handling with no annotations, and I don't have access to the transaction manager.