I'm confused about what is allowed in ejbCreate() and ejbRemove() for stateless BMT beans. According to the EJB spec (page 90) and some notes, you ARE allowed to get the user transaction from the SessionContext object (i.e. getUserTransaction()). But according to HFEjb (page 228) and some other notes, you ARE NOT allowed to get the user transaction.
Which is it? To me, it makes sense that you cannot get the user transaction. Creation of stateless SB's are not tied client calling create(). Only the container will invoke ejbCreate() and ejbRemove(), so you are not in a meaningful transaction context.
The specs says that we can get UserTransaction in ejbCreate() and ejbRemove() methods for stateless session bean with BMT. I understand that getting an UserTransaction has nothing to do with the fact that when the ejbCreate()/ejbRemove() is invoked, there is no client tied to them. Ranchers please correct me if I am wrong.
Nikhil, I guess you are referring to Entity beans.
Answering my own question.. Did some more research and there's a difference between calling getUserTransaction() and actually doing something with it (i.e. UserTransaction.setRollbackOnly())
BMT are allowed to call getUserTransaction() in ejbCreate() and ejbRemove() (CMT beans would get java.lang.IllegalStateException). But since ejbCreate/ejbRemove are run in an unspecified transaction context, you cannot do anything with the user transaction, like setRollbackOnly().
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop