However, for Stateful session beans you have two minor differences: - You can call EJBContext.getCallerPrincipal() and EJBContext.isCallerInRole(). - afterBegin() and beforeCompletion() are invoked with a transaction context. This is not the same for afterCompletion() which is invoked after the transacion has completed.
For entity beans (section 3.5 of the JPA specification):
When invoked from within a Java EE environment, the callback listeners for an entity share the enterprise naming context of the invoking component, and the entity callback methods are invoked in the transaction and security contexts of the calling component at the time at which the callback method is invoked.
[ September 08, 2008: Message edited by: Sergio Tridente ]
I just want to summarize the above reply: For call back listener method: Stateless session beans: unspecified transaction context & security context Stateful session beans: unspecified transaction context & security context Entity: same trasaction & secuirty contexts. In addition, for stateful session beans: afterBegin() and beforeCompletion() - same transaction context but unspecified security context afterCompletion() - unspecified transaction & secuirty context. Please correct me if I am wrong.
But does the afterBegin() and beforeCompletion() belong to the life cycle of a Stateful session bean? In my post I've mentioned only about the lifecycle callbacks if they occur in an unspecified transaction and security context.