Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getUserTransaction method

 
Muthaiah Ramanathan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the ejbCreate or ejbRemove method of a STATELESS SESSION bean class, can we access use the method getUserTransaction() on the session context object?

The book by Paul Sangerra says, we cannot access it and the HFEJB(in the errata page) says it can be accessed. Which is true...?
 
MI Mohammed
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the getUserTransaction() can only be called from both ejbRemove() and ejbCreate() of a BMT Bean. CMT Bean can not call never getUserTransaction() from any of it's methods, says the spec.
 
Aleena Rehman
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cannot use getUserTransaction() in ejbRemove(),ejbCreate() of Stateless Session bean ....

Reason is very simple....
ejbCreate() and ejbRemove() are called by the container at a time when he feels its time to increase/reduce the pool (Not by a client invocation, and therefore this means Transaction will not be available). The methods are called in an "unspecified transaction context", and therefore this method cannot be called.

Regards,
Aleena
 
Muthaiah Ramanathan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I ran a test and it showed that in ejbCreate method of a stateless session bean using BMT, I can successfully get a transaction reference.

Below

And the spec(page 90) also states that we can use getUserTransaction() in the ejbCreate or ejbRemove methods of a stateless session bean using BMT.
 
Aleena Rehman
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a method runs in an unspecified transaction context, means if you use context.getUserTransaction(), the code is not portable. It may work for one server, but not for another. The spec does not mandate containers to ignite a transaction for the methods marked with "Unspecified Transaction Context"

My 2 Cents...
Regards,
Aleena
 
Muthaiah Ramanathan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The spec says we can. So that means it is portable, right?
 
Imran Vohra
Ranch Hand
Posts: 77
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think spec is saying that you can call "getUserTransaction()" method in ejbCreate() & ejbRemove() of stateless bean BUT you cannot call "UserTransaction methods".
 
suman.pulikond a
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if it is like that what is the benefit of getting usertransaction object, If we were unable to call any method in that one for BMP'S.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic