For BMT bean, we have rollback() and setRollbackOnly(). Actuall, why we need both, while both are used to rollback the transaction? Is there any differences is there between rollback() and setRollbackOnly()
Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
BMT and CMT both can call setRollbackonly, the only difference is that BMT should call it on UserTransaction where as CMT should call on it's context. It will be useful only when there is multiple component inlvolves in single transaction and you would like to do transaction commit or rollback based on other component outcome.
Example :
UserTransaction ut = context.getUserTransaction(); ut.begin; OtherComponent oth = new OtherComponent(); oth.doStuff(ut); if(ut.getStatus() == javax.transaction.Status.STATUS_MARKED_ROLLBACK) { ut.rollback(); } else { do some processing ut.commit; }
//OtherComponent
public void doStuff(UserTransaction ut){ do processing1 if(something went wrong){ ut.setRollbackOnly(); } else{ do processing 2 } }
Though above things can be achieved using proper exception handling instead of using setRollbackOnly.
Regards, Rajan
[ May 31, 2007: Message edited by: rajan singh ] [ May 31, 2007: Message edited by: rajan singh ]