• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

getUserTransaction method

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...?
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The spec says we can. So that means it is portable, right?
 
Ranch Hand
Posts: 77
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic