Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

allowed operation in ejbCreate() of stateless session bean

 
Steven Gao Song
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,all

Why we can use the SessionContext to get a reference to the EJB Object
in the ejbCreate() of stateless session bean? When the Container invokes ejbCreate(), there are no client yet! The EJB object has not been linked to
the bean. How could we access the EJB object?


I am confused. Please help me.

Thank you.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

there are no client yet! The EJB object has not been linked to the bean. How could we access the EJB object?


I think you have misunderstood, the ejbCreate() method is a container callback and container call this method when it receives a call on corresponding create() method in home object, means that some client invokes home.create() method. So before calling ejbCreate() container creates the EJB Object for current instance, that is why EJB object is available in this method.

Hope it clarifies.
 
Mahesh Desai
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the time the ejbCreate() method is called, the setSessionContext() method has already been executed, and hence the session context has already been assigned to the bean and the EJBObject for this instance has been created. The container creates an instance, invokes the setSessionContext() method on it to give it a context, and then calls the ejbCreateMethod().


newInstance() --->> setSessionContext() --->> ejbCreate()


This is why we could access EJBObject in ejbCreate() of stateless session bean.


Thanks,
Mahesh

-------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
 
Steven Gao Song
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I cannot understand yet.

Please refer to Page227 HFEJB. When the client calls the create()
on the Home object, EJB Object is created. It has nothing to do with
the ejbCreate() method! Only when the clients invoke the business
methods, the EJB Object is linked with the bean instance.

The container creates the stateless session bean instance without creating
the EJB Object. So, I still think that in ejbCreate() method, it
is impossible to get the reference to bean's EJB object.


Thank you.
 
Shanthala Baleger
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Steven, if you read the page 101, 103, 224 � 227 in Head First Ejb

1. I think Container calls ejbCreate() to create bunch of beans and they will stay in pool.

2. EJBObject gets created when client call create().

3. Only when method gets called on the EJBObject, that is when the Bean comes out of the pool and get bound to the EJBObject.

4. So when ejbCreate() called in stateless bean it would have no clue about the EJBObject.

5. Same thing with ejbRemove(). Bean will be in pool not attached to any EJBObject, when container calls ejbRemove() on bean.

6. when Client calls remove() on the stub, only the Stub and EJBObject () gets removed for that client in stateless session bean.


Experts please please clarify. We have 5 people in out study group, all of us are confused. Please help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic