This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting EJBObject from ejbCreate() on stateless bean

 
Nicholas Way
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the spec (table on page 90), a stateless session bean can call getEJBObject from its ejbCreate() method. My understanding is that ejbCreate() is called when the bean is created, which does not necessarily relate to any client interaction, which means, presumably, that there will be no EJBObject. Is this right, and if so, what happens when getEJBObject is called in such a case. Does it return null (which can be checked for in code), or does it throw an exception?
 
Frederic Esnault
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stateless session bean case is quite simple. In fact, each stateless SB TYPE has ONE EJBObject. Which mean each client accessing the same type of stateless bean will access the SAME EJBObject.

Now on to the creation time. When client calls create(), what is actually created (if not already existing) is the EJBObject. Later, when the bean is needed for business method needs, then container calls its constructor, ties it to an EJBObject, sets its context, and then calls the ejbCreate() method. But at this time, the EJBObject for this type of stateless bean exists for a long time already, so its available in the ejbCreate() method.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!