• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TransactionAttributeType REQUIRED and rollback

 
Ravi Danum
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 580
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,

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

Best regards,
Reza
 
Ravi Danum
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, Reza for this valuable information. Based on your feedback, I may change to REQUIRES_NEW.

Ravi
 
Ravi Danum
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic