According to EJB Spec for stateless session bean in ejbCreate() and ejbRemove() method, you can call getUserTransaction() method (for BMT) but not UserTransaction methods. From this I understood that you can get transaction reference but you cannot call methods on it. Am I right? I am confused as in HFEJB book, that particular point is not checked in ejbCreate() and ejbRemover() methods in stateless session bean.
You are right. In case of stateless beans with Bean Managed Transaction (BMT), you can get a reference to the javax.transaction.UserTransaction object in ejbCreate() and ejbRemove() methods. But you can call methods (eg: commit(), getStatus() )on this object only in business methods.
A generic rule: When in doubt always follow the rule mentioned in EJB specs.
another question is of entity bean - in ejbLoad() & ejbStore() method, you can get security info about client (getCallerPrincipal() & isCallerInRole() method), so why it is not possible to get this info in ejbActivate() and ejbPassivate() method.
Look at the Lifecycle diagram of Entity beans:
ejbLoad() and ejbStore() are performed when the bean is in "method ready state". Although the container determines when to call these methods, they are called due to some client action. (The container cannot on its own modify entries ina database. Isn't it ?) The bean instance is associated with a client context in this state and hence calling those methods are valid.
ejbActivate() and ejbPassivate() calls are initiated by container. The container determines when to initiate these operations based on resource availabilty and several other parameters. Client actions are not involved. Since there is no client context present when these callback methods are called, you cannot call getCallerPrincipal() & isCallerInRole() methods.
[ December 28, 2005: Message edited by: Sankar Subbiramaniam ]