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.
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.
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.
Joined: Sep 20, 2005
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
Joined: May 16, 2005
The spec says we can. So that means it is portable, right?