File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes getUserTransaction method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "getUserTransaction method" Watch "getUserTransaction method" New topic
Author

getUserTransaction method

Muthaiah Ramanathan
Ranch Hand

Joined: May 16, 2005
Posts: 102
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...?


SCJP 1.6, SCJD, SCWCD, SCBCD.

Be nice to people on the way up cos, you'll need 'em on your way down - From somewhere I can't remember!
MI Mohammed
Ranch Hand

Joined: Feb 16, 2005
Posts: 146
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.


SCJA(Beta) SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCBCD 5.0 beta <br />The more practice we get, the better we are at the exams and in life in general. Pls join me at My DEN.
Aleena Rehman
Ranch Hand

Joined: Sep 20, 2005
Posts: 66
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


Aleena Rehman<br />SCJP, SCBCD 95%, SCWCD 85%, IBM-OOAD 84%, SCEA-I 91%
Muthaiah Ramanathan
Ranch Hand

Joined: May 16, 2005
Posts: 102
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

Joined: Sep 20, 2005
Posts: 66
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

Joined: May 16, 2005
Posts: 102
The spec says we can. So that means it is portable, right?
Imran Vohra
Ranch Hand

Joined: Dec 12, 2005
Posts: 77

I think spec is saying that you can call "getUserTransaction()" method in ejbCreate() & ejbRemove() of stateless bean BUT you cannot call "UserTransaction methods".


Regards
Imran
suman.pulikond a
Greenhorn

Joined: Jul 31, 2005
Posts: 11
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getUserTransaction method