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

Accessing another beans methods in setSessionContext()

 
Ben Field
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
The head first book says that you are not allowed to access another beans methods in setSessionContext (page 228 for stateless and 196 for stateful), however I managed to do so using the following code:

Is the book incorrect or have I mis-understood something?
Thanks for any help anyone can give.
 
Mike Cogan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The EJB spec says that,
Accessing resource managers and enterprise beans is disallowed in the session bean methods
for which the Container does not have a meaningful transaction context or client security context.

It also says that
If a session bean instance attempts to access a resource manager or an enterprise bean, and that access is
not allowed (as state by the spec), the behavior is undefined by the EJB architecture.

So your code in theory could work it's just not gauranteed to work in all EJB containers. This hurts your EJB's potential for reusability.
HFEJB is saying what is mandated by the spec so you will need to know it for the exam.
Hope this helps,
Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic