This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getEJBObject in ejbCreate (stateless session bean)

 
Peter Wiederkehr
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Peter Wiederkehr
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Valentin for explanation!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic