File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why can stateless ejbCreate() access EJBObject???

 
parra matta
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateless session bean ejbCreate()is completely decoupled from a clients create() call so how on earth can it get a reference to EJBObject !

A stateless session bean is created by the container when it feels/requires

constructor()
setSessionContext()
ejbCreate()

but at no time in this lifecycle is there any EJBObject so how can you refer to it in ejbCreate() ?

What i knOw is -
the container creates a stateless session bean and put it in the pool and invokes ejbCreate().
Here when ejbCreate() is called by the container, no client ever came along and called EJBHome.create() then no EJBObject would ever be created.
In this case how could a stateless session bean ever refer to an EJBObject if one has never been created.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the EJBObject is generated at the bean's creation. The EJBObject is the identity of the bean.
So I think that there is already an EJBObject when ejbCreate is invoked. It's different for entity beans where the identity has to be created in the ejbCreate.
But I can't find anything clear in the spec. That is a very interesting question and I hope someone can answer it. I'm wondering too.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:
I think that the EJBObject is generated at the bean's creation.


I do not think so.

Originally posted by parra matta:
Stateless session bean ejbCreate()is completely decoupled from a clients create() call so how on earth can it get a reference to EJBObject !


In this case you will get an IllegalStateException.
[ May 16, 2007: Message edited by: Rahul Bhattacharjee ]
 
Alex Sun
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For stateless session bean, when a client calls, ejb instance was from pool, ejbcreate() could be invoked when the client does not exist, but EJBObject is specific for clients.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case you will get an IllegalStateException.

So why allowing it to be called ? The spec clearly shows that it is accessible in ejbCreate.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:

So why allowing it to be called ? The spec clearly shows that it is accessible in ejbCreate.


You get a reference to EJBObject from session context and that is same from stateless session beans and stateful session beans.Probably that is the reason.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But tables describing allowed methods are separated for stateful and stateless beans. I still can't get it.
 
Pradeep Sashidhara
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even I'm confused about this, HFEJB on page 228 says that you can get access to EJBObject for stateless session beans during ejbCreate and ejbRemove, but how is this possible ??? If the sequence of events that is said to happen is to be believed, I'm not able to make out how can a bean get access to it's EJBObject. Has anyone tried out practically, it might be returning NULL !!!
 
NareshAnkuskani Kumar
Ranch Hand
Posts: 76
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this link sorts out the problem

http://www.coderanch.com/t/160199/java-EJB-SCBCD/certification/getEJBObject-setSessionContext
 
Pradeep Sashidhara
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Naresh.

If I got it right, it means that the container does not create the stateless session beans until there's a real demand from the client, i.e. until the client calls a business method on it's component interface. When this happens if there's no free bean in the pool, container creates one and associates the EJBObject to this bean before calling ejbCreate. Hence we have reference to EJBObject in ejbCreate.

Or it might as well have a bunch of EJBObjects created before the creation of bean instances, it might return one of them.


Any difference in opinion ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic