Forums Register Login

getUserTransaction method

+Pie Number of slices to send: Send
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...?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
The spec says we can. So that means it is portable, right?
+Pie Number of slices to send: Send
I think spec is saying that you can call "getUserTransaction()" method in ejbCreate() & ejbRemove() of stateless bean BUT you cannot call "UserTransaction methods".
+Pie Number of slices to send: Send
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.
Clowns were never meant to be THAT big! We must destroy it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1145 times.
Similar Threads
Transactional Context of Session Beans
Doubts in CMT vs BMT beans
getUserTransaction() within ejbCreate()
confusion over bean things
HFE vs EJB Spec - session beans
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:08:32.