File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes SetRollbackOnly in CMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "SetRollbackOnly in CMT" Watch "SetRollbackOnly in CMT" New topic

SetRollbackOnly in CMT

Carlos Llona

Joined: Apr 09, 2004
Posts: 15

What happend if in one method running in CMT I set the transaction to rollback (mycontext.setRollbackOnly())

will the container throws a Exception to the client when the method finish(or the method who colled)???

Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Carlos,

No, container will not throw an exception in this case, it will do the rollback and pass method results (or application exception) back to the caller.

That is what the spec says (section

* The Container must ensure that the transaction will never commit. Typically, the Container instructs the transaction manager to mark the transaction for rollback.

* If the Container initiated the transaction immediately before dispatching the business method to the instance (as opposed to the transaction being inherited from the caller), the Container must note that the instance has invoked the setRollbackOnly() method. When the business method invocation completes, the Container must roll back rather than commit the transaction. If the business method has returned normally or with an application exception, the Container must pass the method result or the application exception to the client after the Container performed the rollback.

Hope it helps

Alex (SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJD 1.4)
Jef Kelly

Joined: Jun 25, 2004
Posts: 8
So this is sort of "quiet rollback"...does this mean that the only way to really alert the caller is to always check getRollbackOnly() and throw an application exception (or return a success boolean)?
Alex Sharkoff
Ranch Hand

Joined: Apr 11, 2004
Posts: 209
Hi Jef,

This is a good approach

I agree. Here's the link:
subject: SetRollbackOnly in CMT
It's not a secret anymore!