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.
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.
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.
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 ]
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?
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().
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.
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().
Failure is not when you fall down; its only when you fail to get up again.
Trust God, but always tether your camel... to this tiny ad.
a bit of art, as a gift, the permaculture playing cards