Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operations allowed in the methods of stateful session bean

 
Dennis Shi
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everybody,

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
 
Gang Zhang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the question I have, so if anyone can answer, that will be help.
 
Forrest Xu
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anyone can answer?
 
Vijay Gopalakrishnan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic