This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Bean things that you can do from stateless bean methods: In the ejbCreate() and ejbRemove() methods, a) get a reference to your home b) get a reference to your EJB object
I can understand (a). But I am not able to understand how (b) can be done.
When ejbCreate() is called by the container, there is no EJBObject in the picture. My understanding is that the ejbCreate() and the client call are not tied to each other for a stateless session bean - the container decides when to create beans. How can we get a reference to EJB object using my session context in this case? Can someone please explain? I am not sure if my understanding is right.
An instance of a session enterprise Bean can call this method at anytime between the ejbCreate() and ejbRemove() methods, including from within the ejbCreate() and ejbRemove() methods.
An instance can use this method, for example, when it wants to pass a reference to itself in a method argument or result.
This made me assume that for a stateless session bean it would simply create an EJBObject instance which the bean instance could then return during its lifetime (in lieu of "this") - which would be perfectly acceptable as no EJBObject instance is linked to any specific instance of the same stateless session bean type anyway.
However, I have no further proof to offer.
Joined: Aug 24, 2005
Joined: Aug 19, 2005
Also do not lose sight of the fact that the EJBObject/Component Interface is a conceptual object/instance. The Server/Container providers can do what they want, as long as they adhere to the contracts outlined in the specification.
I somehow doubt that most containers actually create discrete instances of the various component interfaces unless its done with something like the Flyweight design pattern in front of something that resembles a front-end transaction processor.
So in fact there may already be something out there that can act as the EJBObject for a stateless session bean during the ejbCreate - nothing has to be actually created.