Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rollback() vs setRollbackOnly()

 
Micheal John
Ranch Hand
Posts: 344
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A BMT bean does not (must not) call setRollbackOnly()
 
Mansur Khan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think again...
 
rajan singh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, sorry gives, I misunderstood UserTransaction.setRollbackOnly and EJBContext.setRollbackOnly
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, sorry guys, I misunderstood UserTransaction.setRollbackOnly and EJBContext.setRollbackOnly
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic