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.
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.
But tables describing allowed methods are separated for stateful and stateless beans. I still can't get it.
Joined: May 21, 2007
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 !!!
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.