wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes TransactionAttributeType REQUIRED and rollback 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 "TransactionAttributeType REQUIRED and rollback" Watch "TransactionAttributeType REQUIRED and rollback" New topic
Author

TransactionAttributeType REQUIRED and rollback

Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Hello,

If I am using TransactionAttributeType.REQUIRED for a stateless session bean, and it is called from an object that is already in a transaction, and the stateless session bean persists a row in the database, then returns back to the caller, then an error occurs in the caller code which causes a rollback, will the row which was persisted in the stateless session bean be rolledback also?

Thanks for any help you can give.

Ravi
Reza Rahman
author
Ranch Hand

Joined: Feb 01, 2005
Posts: 580
    
    5
Ravi,

Yes, the EJB work would be rolled back. If this is not what you want, use REQUIRES_NEW instead...

Best regards,
Reza


Independent Consultant — Author, EJB 3 in Action — Expert Group Member, Java EE 6 and EJB 3.1
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Thanks so much, Reza for this valuable information. Based on your feedback, I may change to REQUIRES_NEW.

Ravi
Ravi Danum
Ranch Hand

Joined: Jan 13, 2009
Posts: 104
Hello,

If TransactionAttributeType.REQUIRED is used, and the caller's database code throws an exception. The catch of this exception calls an ErrorLogger stateless EJB which is called to persist an error. Will the ErrorLogger start its own transaction?

Given a different scenario with the following call stack:

caller (stateless session EJB) -> web service (servlet-based web service) -> target (stateless session EJB) -> entity bean

and the target is set with TransactionAttributeType.REQUIRED, then will the target create a new transaction? Notice that there is a servlet-based web service in the middle.

Thanks for your help.

Ravi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TransactionAttributeType REQUIRED and rollback
 
Similar Threads
Throttling requests
BMT and Session beans
Transaction handling in Session Bean
Transactions... guarantee ?
SessionSynchronization interface