Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Transaction in Session Bean

 
SamyV VenkatS
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am preparing for the SCBCD and planning to sit for the exam on the Java Certification Day here in Singapore. I have got a doubt as below.

Referring to page 207 of HeadFirst EJB, under the list of use your session context to i could find 'get a transaction reference and call methods on it (BMT Beans)'. But methods on CMT like force a transaction to rollback and find out whether a transaction has already been rolled back could not be called. How can this be explained? When a bean is in a transaction it cannot be passivated. Isn't this applies to both CMT and BMT? Thanks for any replies..

Kuppusamy
SCJP 1.3
 
Stefan Egger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I know the answer to the second question: Stateful session beans can only keep a transaction open over more than one method invokation when using BMT. With CMT, the transaction has to be completed within the method. Since the container will not attempt to passivate the bean while it is in the middle of a business method (but only when the bean has not been used for some time), this problem will not occur with CMT.

Hope that's correct & helps...

Greets,
Stefan
 
Vagner Freitas
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi SamyV,

I think the answer for your question is on page 499 of HF EJB.
CMT session bean methods ejbCreate(), ejbRemove(), ejbActivate() and ejbPassivate() run in an "unspecified transaction context".
In other words, the create and remove methods os session bean are not considered part of client's transaction and activate and passivate will never be called if the session bean is in a trasaction.
Remember it is true for CMT session beans.
I hope this helps you.

Vagner
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic