This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes EJB 3.0 Nested Transaction Issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB 3.0 Nested Transaction Issue" Watch "EJB 3.0 Nested Transaction Issue" New topic
Author

EJB 3.0 Nested Transaction Issue

Abhishek Bhargav
Greenhorn

Joined: Apr 27, 2011
Posts: 3
Hi All,
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)
Outer Transaction
{
for loop
{
(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
java.lang.Throwable: STACKTRACE
at org.jboss.resource.connectionmanager.CachedConnectionManager.registerConnection(CachedConnectionManager.java:278)
at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:524)


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!
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.commitAndDisassociate(TransactionImple.java:1414)
at com.arjuna.ats.internal.jta.transaction.arjunacore.BaseTransaction.commit(BaseTransaction.java:137)
at com.arjuna.ats.jbossatx.BaseTransactionManagerDelegate.commit(BaseTransactionManagerDelegate.java:75)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:170)


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.


Regards,
Abhishek
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hi Abhishek,
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.

Regards,
Amit
Abhishek Bhargav
Greenhorn

Joined: Apr 27, 2011
Posts: 3
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".

Regards
Abhishek
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
hi,
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.

regards,
Amit
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9915
    
158

Abhishek Bhargav wrote:
But my requirement is when outer transaction timeout occurs, then for loop should terminate.


Read this blog and the comments in that blog.

[My Blog] [JavaRanch Journal]
Abhishek Bhargav
Greenhorn

Joined: Apr 27, 2011
Posts: 3
Hi,

Yes the blog link is good in understanding how internally transaction timeout works, but the solution provided seemed to be a hard nut to crack.

I have set the transation timeout of outer and inner transaction using the annotation @TransactionTimeout(value = 600)

For outer transation I used it at class level @TransactionTimeout(value = 600), for inner transaction used it at method level @TransactionTimeout(value = 300).

Moreover I am using the stateless session bean not stateful.
Thanks for sharing your ideas.

Regards,
Abhishek
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB 3.0 Nested Transaction Issue
 
Similar Threads
JQ+ Question ID :952739443290
Question abt Enhanced For loop
labeled continue statement?
nested try catch finally in a for loop : how does it work
GC Overhead limit exceeded error when reading a text file