File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How a transaction is commited in a CMT

 
Senthil Kumar
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am confused as to when and where the commit is performed for Bean with a
container managed transaction.
 
Shivani Chandna
Ranch Hand
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Senthil Kumar
Ranch Hand
Posts: 264
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic