• 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

ejbCreaten call for stateless session beans

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When is the ejbCreate call actually made for a stateless session bean. From page 227 of headfirst ejb, it looks as though the call is made when the bean is instantiated and placed in the pool. If that is the case, how come the bean has access to the ejb object (through it's sessionContext) in the ejbCreate method?

Since the ejbObject is created at a different point in time (when create is called on the home object) , and then the ejbObject is associated to the bean at a later point (when a business method is called on the component interface) , isn't it logical to expect that the ejbCreate method does not have access to the ejbObject (considering the fact that the ejbCreate method is called during instantiation and not during the ejbObject creation).
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember, when a client calls create on a home interface to "create" a SSB, it's not really creating anything. It's just there to be consistent with the EJB API! (And, of course, to have something returned to the caller -- the EJB stub.)

It's probably better to think of SSBs as more service-oriented (maybe even like static methods, if that helps you). So, "creating" it is just a silly little do-nothing. The bean was actually created a long time ago and has been a full-fledged EJB since it was a little baby. And that's why it had access to its EJBObject from day 1 (ejbCreate). Tada.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shalini,
A very good question. And thanks 4 posting it, as I also had exactly same in mind since quite some time.

Nathaniel,
You say:

Remember, when a client calls create on a home interface to "create" a SSB, it's not really creating anything. It's just there to be consistent with the EJB API! (And, of course, to have something returned to the caller -- the EJB stub.)



Please take a look at diagram on page 227 again. The create() method on EJBHome is creating instance of EJBObject. So it's clearly creating an object of EJBObject. We all know that Bean instances are created separately by Container and it is not linked with client's invocation of EJBHome's create() method.


Shalini,

Would you pls do one favor?

I have tried following code in a Stateless Session Bean. I tried it in Websphere Studio Application Developer. I could not arrive at any conclusion because, Container did not create instances of my Stateless Session Bean in pool unless client called create() method on EJBHome stub.

Can you please try the above code in a Stateless session bean whose instances are created and maintained in pool well before a client's request for create() is received by Container? Please post what are output messages shown on server console or in log file.

 
Sandesh Tathare
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I got an interesting finding.

When IBM WSAD starts server with above Stateless Session Bean. The container does call Constructor of Bean, but calls setSessionContext() and ejbCreate() methods only when a request is recevied from a client. Also note that with processing of client request it also calls Constructor. So it varies from the diagram shown on HF EJB page no. 227. I could verify this by putting some SOPs in Constructor and setSessionContext() method.

Can any one try this out please and comment on the same?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shalini,

I found an excellent thread with regards to your question above (in case you don't already have it):

web page

Hope that clarifies.
 
reply
    Bookmark Topic Watch Topic
  • New Topic