aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Operations allowed in the methods of a stateless session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Operations allowed in the methods of a stateless session bean" Watch "Operations allowed in the methods of a stateless session bean" New topic
Author

Operations allowed in the methods of a stateless session bean

Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90
Page 228 of HFEJB

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.


Regards<br />Ram<br /> <br />SCJP 1.4, SCBCD 1.3, (SCEA)
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
In principle you are correct. However the SessionContext states:

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.


"Don't succumb to the false authority of a tool or model. There is no substitute for thinking."
Andy Hunt, Pragmatic Thinking & Learning: Refactor Your Wetware p.41
Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90
Thanks Peer.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2906
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.
Ramakrishnan Viswanathan
Ranch Hand

Joined: Aug 24, 2005
Posts: 90
Got you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Operations allowed in the methods of a stateless session bean
 
Similar Threads
Access to EJBObject in ejbCreate() of Stateless bean
Is Specification not reasonable on this point?
ejbCreate in session bean
ejbCreate in session bean
A tough one for experienced EJB people - Stateless session bean spec question