On page 80 of the specification, resource manager access and enterprise bean access are allowed in the bean methods ejbCreate, ejbRemove, ejbPassivate, ejbActivate. Why? IMO, since there is no meaningful transactin context( unspecified) in these bean methods, the accesses to resource manager and enterprice bean should not be allowed, just as that specifed in the afterCompletion. Can somebody help? dennis
Even though accessing Resource Managers and EJBs is permitted in unspecified transaction contexts, its behavior is unpredictable in case of failure. Do so at your own risk. It is not guaranteed by the EJB spec. Your question gets answered after the table, in page 81 as below: The ejbCreate<METHOD>, ejbRemove, ejbPassivate, and ejbActivate methods of a session bean with container-managed transaction demarcation execute with an unspecified transaction context. Refer to Subsection 17.6.5 for how the Container executes methods with an unspecified transaction context. Excerpts from 17.6.5: 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. Since the enterprise bean does not know which technique the Container implements, the enterprise bean must be written conservatively not to rely on any particular Container behavior. A failure that occurs in the middle of the execution of a method that runs with an unspecified transaction context may leave the resource managers accessed from the method in an unpredictable state. The EJB architecture does not define how the application should recover the resource managers� state after such a failure.
SCJP, SCWCD, SCBCD, SCEA5
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop