Spec says that the getUserTransaction can be called from ejbCreate and ejbRemove (spec page 90). HFEJB says that - get a transaction reference and call methods on it (BMT) - is not allowed from ejbCreate and ejbRemove (page 228)
What it means is that, you could be able to get a reference to UserTransaction interface in ejbCreate() & ejbRemove() methods. But you could not call any of the methods on it. (LIKE begin(), commit() ....)
But, you can do that from business methods...Just have a closer look at the Table 3 in page 90 (SPEC)
USER TRANSACTION METHODS is note mentioned against ejbCreate & ejbRemove...:-)
Think about getUserTransaction method as something that gives you a reference to a "transaction management interface" (which is exactly what it is ).
You can get the interface to it anytime (as I say in my doc : as soon as the bean becomes a bean, which means as soon as ejbCreate is called (except for entity beans, but they cannot use BMT...)), but you can use it to manage transaction only when you get a meaningful transaction context.
You can get the interface to it anytime ... but you can use it to manage transaction only when you get a meaningful transaction context.
I see another scenario here.
For ejbCreate, ejbRemove, ejbActivate, ejbPassivate of SFSB, HFEJB says that Not Allowed: - force transaction to rollback (CMT) - find out if transaction has been set to rollback (CMT) Allowed: - get transaction reference and call methods on it (BMT)
Here, why BMT is allowed to call methods on the UserTransaction? These methods doesn't run under a meaningful transaction context.
You can NOT get an interface to it any time...if you are not allowed to get the interface of User Transaction through JNDI and you attempt to get it , it gives you a javax.naming.NameNotFoundException..
From the spec (first paragraph page 81), it is said that ejbCreate, ejbRemove, ejbPassivate and ejbActivate from a CMT session bean execute in an unspecified transaction context. This is why get/setROllbackOnly is not allowed.
About BMT stateful session beans, as soon as ejbCreate is called, they are linked to a user, so they have a UserTransaction they can use immediately, as developped in the bean.
CMT does not allow tx in these methods, but BMT (where tx management is left up to the bean provider responsability) doesn't restrict tx usage in these methods.