-
Rollback for a Container managed transaction bean (4 messages)
- Posted by: Simo Cussonet
- Posted on: May 25 2009 10:55 EDT
Hello all, I can't find a clear answer for this question neither in the spec nor on the forum. So, I have an EJB 2.1 using CMT. In which cases will the container rollback the transaction it started for the EJB? Does it depends on the type of exception encountered by the bean (SQLexception only for example)? For information, we plan to use stateless and statefull EJB 2 and before using CMT, we want to be sure to get the concept. thanks in advance for your answers, FFFThreaded Messages (4)
- Exception handling by Guy Pardon on May 26 2009 02:34 EDT
- Re: Rollback for a Container managed transaction bean by shreenee josh on June 02 2009 05:54 EDT
- RuntimeExceptions by Tarun Arora on June 09 2009 01:56 EDT
- Nope, CMT and userTransaction are incompatible by Kingsly Thewdar on February 05 2010 16:09 EST
-
Exception handling[ Go to top ]
- Posted by: Guy Pardon
- Posted on: May 26 2009 02:34 EDT
- in response to Simo Cussonet
Referring to EJB spec 2.1, page 400, table 15 -> this contains the information you need. Basically, 'application-level' (checked) exceptions do NOT automatically lead to rollback. But I recommend reading the exception handling chapter to get the details. Best Guy http://www.atomikos.com Tired of EJB? Try JEE without application server :-) -
Re: Rollback for a Container managed transaction bean[ Go to top ]
- Posted by: shreenee josh
- Posted on: June 02 2009 05:54 EDT
- in response to Simo Cussonet
Hello all,
Since you are using CMT, you should mark transaction for rollback using userTransaction.setRollbackOnly().
I can't find a clear answer for this question neither in the spec nor on the forum.
So, I have an EJB 2.1 using CMT. In which cases will the container rollback the transaction it started for the EJB? Does it depends on the type of exception encountered by the bean (SQLexception only for example)?
For information, we plan to use stateless and statefull EJB 2 and before using CMT, we want to be sure to get the concept.
thanks in advance for your answers,
FFF -
RuntimeExceptions[ Go to top ]
- Posted by: Tarun Arora
- Posted on: June 09 2009 01:56 EDT
- in response to shreenee josh
CMT transactions will automatically be rolled back for any RuntimeException. Additionally if you want to rollback on a checked exception, you need to catch the exception and set the rollback for transaction through sessioncontext. Only glitch here is in case of manual rollbacks (sessionContext.setRollback) the control is not abrupted rather the whole method executes but nothing will be committed when the method completes since the transaction is marked for roll back. So as a best practice it is recommended that when you design a session facade doin more than one JDBC update operations before each operation you must check for Rollback status. If the transaction is already set for rollback one need not execute the 2nd jdbc operation Eg. Pseudo Code // first jdbc operation try { }catch(NoAccountException ne) { sessionContext.setRollback; } if(!sessionContext.isRollback) { // Do Second Operation } -
Nope, CMT and userTransaction are incompatible[ Go to top ]
- Posted by: Kingsly Thewdar
- Posted on: February 05 2010 16:09 EST
- in response to shreenee josh
Since you are using CMT, you should mark transaction for rollback using userTransaction.setRollbackOnly().
CMT and userTransaction are incompatible.