File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes System exception in a BMT 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 "System exception in a BMT" Watch "System exception in a BMT" New topic
Author

System exception in a BMT

Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
Consider the scenario:
1) A BMT session bean starts a transaction in a business method
2) Before the txn is committed, a system exception occurs
3) According to specs (page: 377, Table 16), container would mark the transaction for rollback and discard the bean.

Question: When will the transaction be rolled back ? Is it when the bean is discarded ?
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
yes, when a bean throws a system exception to the container, the container kills the bean, does a rollback of the transaction, logs the exception and throws a RemoteException to remote clients and EJBException to local clients irrespective of whether it is CMT or BMT. This would typically happen immediately after the exception is thrown
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
yes, when a bean throws a system exception to the container, the container kills the bean, does a rollback of the transaction, logs the exception and throws a RemoteException to remote clients and EJBException to local clients irrespective of whether it is CMT or BMT. This would typically happen immediately after the exception is thrown


Container does the rollback of transaction only if it has started the transaction. In case of BMT (according to specs 377, Table 16, page 378 Table 18), container only marks the transaction for rollback.

So my question once again: In case of BMT after a system exception is thrown When does the rollback of txn happen ?
Devender Thareja
Ranch Hand

Joined: Jul 14, 2005
Posts: 187
Once the bean throw a system exception to container, the bean is possibly corrupt. The control is not going back to bean now. The container will rollback the transaction and throw a RemoteException or EJBException (local) to client (if there is a client). The bean will be killed.


Devender Thareja
SCEA, SCBCD, SCJP
B.Sathish
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
This is how I understand it. In case of BMT, rollback will happen only if ut.rollback() is called. As Devender said, once a System Exception is thrown to the container, control is not going back to the bean. So ut.commit() or ut.rollback() can never be executed in that transaction context. That means what happens to the transaction? Can you say it is NOT committed (because ut.commit() is not executed). A non-commited transaction or in other words, an abandoned transaction is as good as one that's rolled back right?
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
Abandoned transaction as good as committed transaction

How can it be ? Committed transaction - releases resources / locks etc.
Abandoned transaction - the txn is live holding on to resources / locks.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
It is quite simple what happens, regardless of whether it is a CMT or BMT session bean. Once a system exception is thrown by a bean method, the container will mark the transaction for rollback. Typically, the container will delegate to a transaction manager the job of actually doing the rollback of the transaction. Therefore, the transaction will be properly completed.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
That clarifies. Thanks Roger.
 
Consider Paul's rocket mass heater.
 
subject: System exception in a BMT
 
Similar Threads
Application Exception thrown by Bean with BMT
Transaction Query
Transaction in MDB
Doubt from ejbcerticate mock exam
MDB tx rollback question