• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Why can stateless ejbCreate() access EJBObject???

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stateless session bean ejbCreate()is completely decoupled from a clients create() call so how on earth can it get a reference to EJBObject !

A stateless session bean is created by the container when it feels/requires

constructor()
setSessionContext()
ejbCreate()

but at no time in this lifecycle is there any EJBObject so how can you refer to it in ejbCreate() ?

What i knOw is -
the container creates a stateless session bean and put it in the pool and invokes ejbCreate().
Here when ejbCreate() is called by the container, no client ever came along and called EJBHome.create() then no EJBObject would ever be created.
In this case how could a stateless session bean ever refer to an EJBObject if one has never been created.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the EJBObject is generated at the bean's creation. The EJBObject is the identity of the bean.
So I think that there is already an EJBObject when ejbCreate is invoked. It's different for entity beans where the identity has to be created in the ejbCreate.
But I can't find anything clear in the spec. That is a very interesting question and I hope someone can answer it. I'm wondering too.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
I think that the EJBObject is generated at the bean's creation.



I do not think so.

Originally posted by parra matta:
Stateless session bean ejbCreate()is completely decoupled from a clients create() call so how on earth can it get a reference to EJBObject !



In this case you will get an IllegalStateException.
[ May 16, 2007: Message edited by: Rahul Bhattacharjee ]
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For stateless session bean, when a client calls, ejb instance was from pool, ejbcreate() could be invoked when the client does not exist, but EJBObject is specific for clients.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In this case you will get an IllegalStateException.


So why allowing it to be called ? The spec clearly shows that it is accessible in ejbCreate.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:

So why allowing it to be called ? The spec clearly shows that it is accessible in ejbCreate.



You get a reference to EJBObject from session context and that is same from stateless session beans and stateful session beans.Probably that is the reason.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But tables describing allowed methods are separated for stateful and stateless beans. I still can't get it.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even I'm confused about this, HFEJB on page 228 says that you can get access to EJBObject for stateless session beans during ejbCreate and ejbRemove, but how is this possible ??? If the sequence of events that is said to happen is to be believed, I'm not able to make out how can a bean get access to it's EJBObject. Has anyone tried out practically, it might be returning NULL !!!
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this link sorts out the problem

https://coderanch.com/t/160199/java-EJB-SCBCD/certification/getEJBObject-setSessionContext
 
Pradeep Sashidhara
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Naresh.

If I got it right, it means that the container does not create the stateless session beans until there's a real demand from the client, i.e. until the client calls a business method on it's component interface. When this happens if there's no free bean in the pool, container creates one and associates the EJBObject to this bean before calling ejbCreate. Hence we have reference to EJBObject in ejbCreate.

Or it might as well have a bunch of EJBObjects created before the creation of bean instances, it might return one of them.


Any difference in opinion ?
 
Sasparilla and fresh horses for all my men! You will see to it, won't you tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic