Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

getEJBObject() in ejbCreate() for SLSB

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to HF EJB page 228, I can get a reference to my EJB object in ejbCreate() for stateless session bean, but on page 225-227, it says bean creation is independent of the user, the EJB object is tied to the bean only when client calls a business method. So my question is if the EJB object is not tied to the bean during ejbCreate(), how can I get reference to EJB object? It does not make sense, right?
Thanks.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here we are talking about 2 different things.
1. EJB Object and 2. Bean instance
We can get the EJBObject during the ejbCreate() method. But the bean instance is pulled from the pool and associated to the client only during the business method call.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Li


According to HF EJB page 228, I can get a reference to my EJB object in ejbCreate() for stateless session bean, but on page 225-227, it says bean creation is independent of the user, the EJB object is tied to the bean only when client calls a business method. So my question is if the EJB object is not tied to the bean during ejbCreate(), how can I get reference to EJB object? It does not make sense, right?


The bean is actually tied with the EJB object. When the container starts up, it will *PRE-CREATE" stateless session bean (depends on vendor whether this happens) and put those beans into the stateless bean pool.
Thus, when the client call ejbCreate(), it does NOT mean the client is now ask the container to create a new stateless bean, BUT it does ask the container to give him a stateless bean from the bean pool.
Does this make more sense?
For Stateful bean, when ejbCreate() invokes, it really DOES create the bean at the time that the method is called.
Nick.
 
Li Xin
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But the diagram in page 225-227 of HF EJB book shows that the bean instance is NOT tied to any EJB Object during ejbCreate() for SLSB, so how to get the EJB Object?
 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that page 225 is missing the ejbCreate() part of the object creation. I imagine that the ejbObject is created at some point during or before this method. There will be only one ejbObject for a stateless session bean per home. A bean instance is pulled from the pool and tied to the ejbObject to service a business method. The bean is put back into the pool upon the completion of the business method.
If you think about it, the only thing that makes sense is for the ejbObject to be created upon bean creation. How else would clients be able to get a reference to the bean in order to call methods on it.
Hope this helps.
[ February 13, 2004: Message edited by: Keith Rosenfield ]
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I do share similar problem with Li. If you look at the EJB Spec (rather than HFEJB which isnt the formal doc afterall ) p92, Fig 12, the object interaction diagram shows a EJB(Local)Object is created when (or until) the client calls the home.create(). And on p94 Fig 15, when the container creates some slsb instance in the method ready pool, it creates instance of the bean class, SessionContext and calls the ejbCreate().
So, ejbCreate() should not be able to get the associated EJB(Local)Object as it isnt created until client calls home.create().
Am i right?
 
Li Xin
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, my idea is exactly the same as Lee's, and also according the HF EJB book, the EJB object is not linked with the bean until the business method is invoked, so if this is true, getEJBObject makes sense ONLY when calling business method, not when the bean is created by the container or client calls home.create().
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So my question is if the EJB object is not tied to the bean during ejbCreate(), how can I get reference to EJB object? It does not make sense, right?


What is important is to know that the container must somehow comply with the EJB 2.0 spec which stipulates that, for a stateless session bean, the EJBObject must be available in the ejbCreate() method. Quite how the container does this is unknown to us, and fortunately we have no need to know (either for the exam or for our day job). Indeed, I would argue that it is highly undesirable for a developer to get knowledgable about the inner workings of a server.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I would support Keith because ..one home for SLSB would have one EJBObject()...which is created after the constructor(),setSessionContext() an before the ejbCreate()...so that we are comfortable to get an
ejbObject().
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic