Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setRollBackOnly Doubt

 
Giju George
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am preparing for my SCBCD exam using the HFEJB book. It seems to be an excellent book. well my doubt is, setRollBackOnly is something like a flag to notify the other concurrent methods taking part in transaction that something bad is going to happen. So that those methods can first check this flag and decide whether to proceed or not. My question is , why do we want to proceed with the next concurrent method in transaction if we set the "setRollbackOnly" flag. Why don't we just rollback right from there ??
 
Suman Sarker
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Giju,
I think you already know that getRollbackOnly() and setRollbackOnly() methods are used by beans with container managed transactions. In CMT, you have no way to rollback a transaction because there is no rollback() method available to do that. Remember rollback method is only available to the BMT beans. If you do not want to proceed with the next method in transaction, you can throw application exceptions, but again throwing application exceptions do not automatically cause the transaction to roll back. So you have to mark the transaction for rollback by calling setRollbackOnly() before throwing the exception.

Hope this helps
Suman
 
Sujatha Kumar
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just would like to add one more note...

setRollbackOnly is mainly useful when the application exceptions are thrown, It gives a chance to the client to recover from the exceptions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic