aspose file tools*
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
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "SetRollbackOnly in CMT" Watch "SetRollbackOnly in CMT" New topic
Author

SetRollbackOnly in CMT

Carlos Llona
Greenhorn

Joined: Apr 09, 2004
Posts: 15
Hello:

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)???

thanks
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 17.6.2.8):


* 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
Greenhorn

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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SetRollbackOnly in CMT