GeeCON Prague 2014*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes getEJBObject() in ejbCreate() for SLSB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "getEJBObject() in ejbCreate() for SLSB" Watch "getEJBObject() in ejbCreate() for SLSB" New topic
Author

getEJBObject() in ejbCreate() for SLSB

Li Xin
Ranch Hand

Joined: Feb 06, 2004
Posts: 37
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.
Dilli raj
Greenhorn

Joined: Jan 31, 2004
Posts: 24
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.


SCJP,SCWCD,SCBCD
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Li Xin
Ranch Hand

Joined: Feb 06, 2004
Posts: 37
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?
Keith Rosenfield
Ranch Hand

Joined: Nov 25, 2003
Posts: 277
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 ]

Keith Rosenfield<br />SCJP<br />SCWCD<br />SCBCD
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
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

Joined: Feb 06, 2004
Posts: 37
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().
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
pradeep arum
Ranch Hand

Joined: Oct 01, 2003
Posts: 130
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().


SCJP1.4,SCBCD
Failure is not when you fall down; its only when you fail to get up again.
 
GeeCON Prague 2014
 
subject: getEJBObject() in ejbCreate() for SLSB