• 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:

Access to EJBObject from within ebjCreate of a stateless SessionBean

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
on page 227 (Head First EJB) it says that ejbCreate is invoked by the container without a client request. On the following page, however, it says that you can get a reference to your EJBObject from within ejbCreate. How can you get such a reference when the container invokes ejbCreate without any client request? Isn't an EJBObject instance only created when the client invokes create on his home object stub (whereas the EJBObject instance is not linked to an actual bean instance until a business method call)?
Thanks,
Kev
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kev Miller:
Hi,
on page 227 (Head First EJB) it says that ejbCreate is invoked by the container without a client request. On the following page, however, it says that you can get a reference to your EJBObject from within ejbCreate. How can you get such a reference when the container invokes ejbCreate without any client request? Isn't an EJBObject instance only created when the client invokes create on his home object stub (whereas the EJBObject instance is not linked to an actual bean instance until a business method call)?
Thanks,
Kev



I tried to figure out how and but could not come up with an answer for Kev's question. Any one..any explanation for this?
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
on page 227 (Head First EJB) it says that ejbCreate is invoked by the container without a client request. On the following page, however, it says that you can get a reference to your EJBObject from within ejbCreate. How can you get such a reference when the container invokes ejbCreate without any client request? Isn't an EJBObject instance only created when the client invokes create on his home object stub (whereas the EJBObject instance is not linked to an actual bean instance until a business method call)?

I don't remember the context on page 227, but I'll attempt to answer your question. Unlike entity bean and SFSB, the ejb container will invoke SLSB ejbCreate when creating a pool of SLSB.

...it says that you can get a reference to your EJBObject from within ejbCreate. How can you get such a reference when the container invokes ejbCreate without any client request?



It means you as a bean developer can get a reference to the EJBObject
 
Ana Nava
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


It means you as a bean developer can get a reference to the EJBObject[/QB]



So what I infer from this is that for every Stateless Session Bean in the pool there is corresponding EJBObject/EJBLocalObject created by the container to which a bean can get reference to. That doesn't sound right to me.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nope, it ain't right. What happens is that the creation of the EJBObject is tied to the creation of the Home object. It is only when the client invokes a business method on the EJBObject's stub that the container will pull a bean instance from the pool and associate the instance with its SessionContext and EJBObject by invoking the bean's setSessionContext() and ejbCreate() methods.
 
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 was wondering exactely how it was possible too because you don't have any clients at this point.

And I have made a search on this forum and found a good post about it. In this post you have the response formulated by Kathy Sierra.

Here is the link:

https://coderanch.com/t/158485/java-EJB-SCBCD/certification/beanness-stateless-session-bean

Cheers,
Adri
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm also having the same question. not only kathey says that. In valentinez cheat sheets also it says you can get reference to ejb object in a stateless beans session object. And the best thing is one mock exam (Soft SCBCD or www.ejbcertificate.com ) question said you cannot do this. So i'm also confused.
but I can still guess of something possible, which is similar to Roger Chung-Wee's suggestion. I think the container does not execute the ejbCreate the bean instance in the actual creation but when the client calls a buisness method.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Stateful Session beans-
we know that the client maintains the life cycle of the bean, so we can have access to EJBObject in ejbCreate() method.

For Stateless Session Beans:-
The Spec says that "To the client, it appears as if the client controls
the life cycle of the session object. However, the container handles the create and remove calls without necessarily creating and removing an EJB instance".

So we can access the EJBObject in the ejbCreate() of the Stateless Session bean.

NOTE:
isIdentical(EJBObject ejbObject) will always return true for Stateless Session beans.
 
Ana Nava
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Adri and Roger ... now it is clear.

Quote from Vijay Dasari

However, the container handles the create and remove calls without necessarily creating and removing an EJB instance".

So we can access the EJBObject in the ejbCreate() of the Stateless Session bean.



Vijay, the question here is "BECAUSE" the Statless session bean is created at the will of the Container and not the client, how can it have access to EJBObject.

The OID both HFEJB page : 227 and in spec Page : 92 suggest that the new EJBObject is created when the "client" calls create method of Home interface. So by this diagram one can come to a conclusion that during ejbCreate() of stateless session bean we cannot get access to EJBObject, because it will be created only when the client calls create() method.

But from Kathy's response (thanks to Adri Smith for pointing me to it) it appears that EJBObject can be created anytime and the bean's context will get reference to it during ejbCreate().

Quote from Roger Chung-Wee

that the container will pull a bean instance from the pool and associate the instance with its SessionContext and EJBObject by invoking the bean's setSessionContext() and ejbCreate() methods.



Roger, according to both life-cycle diagram and OID, setSessionContext() and ejbCreate() are called before the bean comes to the pool.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The OID both HFEJB page : 227 and in spec Page : 92 suggest that the new EJBObject is created when the "client" calls create method of Home interface. So by this diagram one can come to a conclusion that during ejbCreate() of stateless session bean we cannot get access to EJBObject, because it will be created only when the client calls create() method.


You are understandably getting confused about this. When the spec's OID says that the creation of an EJBObject is triggered by the invocation of the create() method of the home interface, this is not to be taken literally. It just means that this is how you should think about it, ie the EJBObject is created and its stub is returned to the client. But remember, as the EJBObject is accessible from the instance's ejbCreate() method, which will certainly be invoked on server startup if that bean type is pooled, then the obvious deduction is that the EJBObject, or something which can return the EJBObject's reference, must therefore available in this scenario before the client invokes create().

The best way I can think of describing this is to say that there are two viewpoints.

From the client perspective, the EJBObject is created when the home interface create() method is invoked.

From the bean perspective, the EJBObject is created after setSessionContext() is invoked but before ejbCreate() is invoked.
 
Ana Nava
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Roger, thanks for explaining again.

I am NOT confused. I just restated the initial confusion, and the reason for that confusion to Vijay. That is the reason I stated that "One can come to a conclusion". From Kathy's response, I clearly understood that creation of EJBObject is not as sequential as depicted in OID.

Also for sure setSessionContext and ejbCreate are called before the bean comes to the pool. No CONFUSION on that

Thanks again .
 
permaculture is a more symbiotic relationship with nature so I can be even lazier. Read tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic