• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

allowed operation in ejbCreate() of stateless session bean

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic