Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes How a transaction is commited in a 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 "How a transaction is commited in a CMT" Watch "How a transaction is commited in a CMT" New topic
Author

How a transaction is commited in a CMT

Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
i am confused as to when and where the commit is performed for Bean with a
container managed transaction.


when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
For CMT & Stateless and Stateful session bean - commit/rollback has to happen before the method ends. Rollback happens if the context.setRollback() flag is set.

For BMT transaction can span method calls.

Hmm.. what if use BMT and EntityManager with FlushModeType as commit and do not call flush on EntityManager before the method ends? Does it result in an exception?.

Shivani


/** Code speaks louder than words */
Senthil Kumar
Ranch Hand

Joined: Mar 13, 2006
Posts: 264
shivani,i want you to check what you have typed.

BMT stateless bean method should commit a transaction before it returns.Else EJBException is thrown.

At the same time Stateful Bean with BMT, we can pass the buck to other metrhods to commit it.However we cant start another transction when there is already one waiting to be commited(i.e client is associated with the transaction context).if you try begin an another transaction NotSupportedException will be thrown.

coming to CMT,
we would not specify the Stateless Session Bean as CMT, since as we know the same bean instance may not be available to service the next method.

what i want to know is we don't issue the commit explicitly in CMT. Then where and how it is getting commited.
Shivani Chandna
Ranch Hand

Joined: Sep 18, 2004
Posts: 380
For BMT transaction can span method calls.

Correction : that should have been BMT +Stateful


we would not specify the Stateless Session Bean as CMT, since as we know the same bean instance may not be available to service the next method.

But we can specify - There is no restriction as such.


what i want to know is we don't issue the commit explicitly in CMT. Then where and how it is getting commited.


It gets committed unless - the method or any method in another bean in the same transaction propagated calls setRollbackOnly() or ApplicationException is thrown which has rollback marked as true. See the Core Specs - 14.2.1:


An application exception does not automatically result in marking the transaction for rollback unless the ApplicationException annotation is applied to the exception class and is specified with the rollback element value true or the application-exception deployment descriptor element for the exception specifies the rollback element as true .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How a transaction is commited in a CMT