• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How a transaction is commited in a CMT

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am confused as to when and where the commit is performed for Bean with a
container managed transaction.
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic