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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "getEJBObject in ejbCreate (stateless session bean)" Watch "getEJBObject in ejbCreate (stateless session bean)" New topic
Author

getEJBObject in ejbCreate (stateless session bean)

Peter Wiederkehr
Greenhorn

Joined: Jul 15, 2004
Posts: 14
Hi javaranch-people

I've read the HF EJB and now have a Question.
In a stateless session bean it is possible to call getEJBObject in the ejbCreate method (page 228). My Question is, WHY?
Stateless session beans are pooled, the constructor, setSessionContext and the ejbCreate are called before a client calls create on the home interface (if the server pool stateless session beans at the startup). So is it possible to call the getEJBObject in ejbCreate because it doesn't matter which EJBObject is returned? Does the server create one if I call getEJBObject in ejbCreate and when a client invokes create on the home this instance is returned to the client?

Thx for any suggestion

Peter


SCJP 1.4<br />SCBCD 1.3
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
So is it possible to call the getEJBObject in ejbCreate because it doesn't matter which EJBObject is returned?
Yes, that's right. Section 6.9.2 of the EJB 2.0 spec states that all session objects of the same stateless session bean within the same home have the same object identity assigned by the container. So it doesn't really matter which EJBObject is returned.

Does the server create one if I call getEJBObject in ejbCreate and when a client invokes create on the home this instance is returned to the client?
I'm not sure I understand the question, could you rephrase please? Thanks


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Peter Wiederkehr
Greenhorn

Joined: Jul 15, 2004
Posts: 14
Originally posted by Valentin Crettaz:
So is it possible to call the getEJBObject in ejbCreate because it doesn't matter which EJBObject is returned?
Yes, that's right. Section 6.9.2 of the EJB 2.0 spec states that all session objects of the same stateless session bean within the same home have the same object identity assigned by the container. So it doesn't really matter which EJBObject is returned.


Really thx 4 the answer /bow

Originally posted by Valentin Crettaz:
Does the server create one if I call getEJBObject in ejbCreate and when a client invokes create on the home this instance is returned to the client?
I'm not sure I understand the question, could you rephrase please? Thanks [/QB]


:roll: ok let me rephrase it:
Assumption:
I call getEJBObject in the ejbCreate and no EJBObject exists. Now the server has to create an EJBObject.
<some time later>
A Client invokes create on the home interface. Which EJBObject is returned, a new one or the EJBObject the server has created when getEJBObject was called in ejbCreate?

I think the answer is: It doesn't matter
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
You are right, it doesn't matter since all EJBObject of the same stateless session bean have the same identity, that is, ejbObject1.isIdentical(ejbObject2) yields true.
Peter Wiederkehr
Greenhorn

Joined: Jul 15, 2004
Posts: 14
Thx Valentin for explanation!
 
 
subject: getEJBObject in ejbCreate (stateless session bean)