• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getEJBObject in ejbCreate (stateless session bean)

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx Valentin for explanation!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic