• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

getEJBObject in ejbCreate (stateless session bean)

 
Greenhorn
Posts: 14
  • 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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Valentin for explanation!
 
when your children are suffering from your punishment, tell your them it will help them write good poetry when they are older. Like this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic