I am facing one issue while implementing Nested Transactions in EJB3.0
I am using contained managed persistence.
The transaction model that I am using for this is explained below:
I have an outer transaction having transation timeout of 10 minutes, it contains a "for loop" which calls another method of session bean that spawn new transaction using "Requires_New" having transation timeout of 5 minutes for each iteration as I need to commit database changes for each iteration independently.
Basic structure I am following =====================
(Timeout is 10 min)
(Timeout is 5 min)
spawn a new transaction - (as need to commit independently for each iteration)
//It does some business logic
Now the problem that I am facing is, when the outer transaction timeout happens after 10 min then the "for loop" is not terminated rather than it continue the processing for remaining iterations also.
After 10 min when outer transaction timeout happens, following error occurs in the CONSOLE 10:18:10,540 INFO [CachedConnectionManager] Closing a connection for you. Please close them yourself: org.jboss.resource.adapter.jdbc.jdk6.WrappedConnectionJDK6@a1638f
But "for loop" continues the processing for the remaining iterations. Once 'for loop" is done, the following error occurs Caused by: javax.transaction.RollbackException: [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] [com.arjuna.ats.internal.jta.transaction.arjunacore.inactive] The transaction is not active!
All the data got commited even after the above exception. Inner transaction timeout is handled perfectly but facing problem for outer transaction timeout.
But my requirement is when outer transaction timeout occurs, then for loop should terminate.Let suppose if outer transaction timeout occurs when inner transaction is processing the business logic, then that changes shuold sink with database, but when next iteration occurs then "for loop" should exit.Is it possible.
Waiting for reply.
First of all this is not the nested transaction. Please check this to understand more on Netsted Transactions. This is just one of the links I found on google.
When you call another transactional method ( Requires_new) in another SLSB, it suspends the existing transaction and then starts a new one.
Additionally your timeout in one method will not be able to stop the processing of another bean's method. There is no notification mechanism between them , isnt it?
For that you will need to poll some kind of variable which will tell you if timeout has happened and stop the FOR loop.
Joined: Apr 27, 2011
Thanks for reply.
Is there any way to track the transaction state whether it is rollbacked or commited or timed out so that we can break the "for loop".
Joined: May 14, 2004
I am not aware of such thing. In Stateful beans you can register the listener that has callback to listen for Transaction lifecyle events.
Apart from this I would like to know how you are setting the transaction timeout ? That might has some clue for the problem.