This week's book giveaway is in the Java 9 forum.
We're giving away four copies of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications and have Sander Mak & Paul Bakker on-line!
See this thread for details.
Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJBObject reference in stateless ejbCreate() ?  RSS feed

 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can a stateless session bean get a reference to the EJB Object in the ejbCreate().
Its clearly mentioned in HFEJB that the bean creation(setSessionContext + ejbCreate) occur at a completely different/unrelated time from the client called Home.create() when the EJBObject is created.
What am I missing?
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The EJBObject is created when the client requests the bean, but the EJBObject just points to a bean in the pool.

When the Bean finishes its work it goes back to the pool, the EJBObject is still there if the client needs it, but it may grab a different bean from the pool for the next request
 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still confused. Let me rephrase a bit. The container calls the stateless session bean ejbCreate() just prior to putting it in the pool.

Container adds a bean to the pool
bean.newInstance()-> bean.setSessionContext() -> bean.ejbCreate()

The EJBObject is created in direct relation to the client calling a Home.create() which generally occurs much later.

Client invoked create
EJBHome.create() -> EJBObject.newInstance()

So, how can the bean instance access the SessionContext.getEJBObject() from the ejbCreate() when there is no EJBObject associated?
Thx in advance.
 
Keerthi P
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its clearly mentioned in HFEJB that the bean creation(setSessionContext + ejbCreate) occur at a completely different/unrelated time from the client called Home.create() when the EJBObject is created.


I'm not sure what HF EJB mentions about the above quote. But according to the spec, it is the container's responsibility to make sure that the EJBObject is made available in the ejbCreate() of a bean instance. So the only possibility is that the EJBObject should have been instantiated by the container before ejbCreate() is called.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!