It's not a secret anymore!
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes setRollBackOnly Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "setRollBackOnly Doubt" Watch "setRollBackOnly Doubt" New topic

setRollBackOnly Doubt

Giju George
Ranch Hand

Joined: Jun 08, 2004
Posts: 333
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 ??

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCEA
Suman Sarker
Ranch Hand

Joined: May 06, 2004
Posts: 68
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 A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!
Sujatha Kumar
Ranch Hand

Joined: Jan 05, 2004
Posts: 134
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.

I agree. Here's the link:
subject: setRollBackOnly Doubt
It's not a secret anymore!