Question#1) Per Table 2 (page 80 of Spec), access to resource managers and other enterprise beans is allowed for ejbCreate(), ejbRemove(), ejbActivate() and ejbPassivate().
Hence I suppose you are not in a meaningful transaction context. If that is the case, how can you access another bean's methods and have resource manager access?
As you had mentioned, there is no meaningful transaction context. However, all these 4 methods are executed by the container in an 'unspecified transaction context' (for CMT). The chapter on Transactions talks about this behavior.
[I] Quoted from sec 17.6.5 of
EJB Spec
The EJB specification does not prescribe how the Container should manage the execution of a method with an unspecified transaction context�the transaction semantics are left to the Container implementation. Some techniques for how the Container may choose to implement the execution of a method with an unspecified transaction context are as follows (the list is not inclusive of all possible strategies):
� The Container may execute the method and access the underlying resource managers without a transaction context.
� The Container may treat each call of an instance to a resource manager as a single transaction (e.g. the Container may set the auto-commit option on a
JDBC connection).
� The Container may merge multiple calls of an instance to a resource manager into a single transaction.
� The Container may merge multiple calls of an instance to multiple resource managers into a single transaction.
� If an instance invokes methods on other enterprise beans, and the invoked methods are also designated to run with an unspecified transaction context, the Container may merge the resource manager calls from the multiple instances into a single transaction.
� Any combination of the above.
Quesion# 2) Same as #1
Question #3) Please refer to
this thread Question #4)
Ref 10.5.3 of Spec
public void ejbActivate();
The container invokes this method on an entity bean instance at activation time (i.e., when the instance is taken from the pool and assigned to an entity object identity). The container must ensure that the primary key of the associated entity object is available to the instance if the
instance invokes the getPrimaryKey(), getEJBLocalObject(), or getEJBObject()
method on its EntityContext interface.
When the container decides to call ejbActivate(), the bean is still 'referenced' - which means the primary key is available. It is however true that the bean instance is not ready to serve a business call as it is not yet loaded with persistent data. We need to wait until ejbLoad for the sync-up.