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 ??
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
Suman A Sarker<br />SCJP, SCWCD, SCBCD<br /> <br />If You Can't Beat Them ... Join Them!