aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Why can stateless ejbCreate() access EJBObject??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Why can stateless ejbCreate() access EJBObject??? " Watch "Why can stateless ejbCreate() access EJBObject??? " New topic
Author

Why can stateless ejbCreate() access EJBObject???

parra matta
Ranch Hand

Joined: Mar 23, 2006
Posts: 40
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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 ]

Rahul Bhattacharjee
LinkedIn - Blog
Alex Sun
Ranch Hand

Joined: Mar 23, 2007
Posts: 42
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.


SCJP 5
SCWCD 1.4
SCDJWS 1.4
SCBCD 5
SCEA 5 (Part 1 cleared)
IBM Certified Solution Developer - WPS 6.1
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

But tables describing allowed methods are separated for stateful and stateless beans. I still can't get it.
Pradeep Sashidhara
Greenhorn

Joined: May 21, 2007
Posts: 8
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 !!!


--------------<br />Pradeep<br />SCBCD 1.3 97%<br />SCWCD 97%<br />SCJP 1.5 93%
NareshAnkuskani Kumar
Ranch Hand

Joined: Sep 15, 2005
Posts: 76
I think this link sorts out the problem

http://www.coderanch.com/t/160199/java-EJB-SCBCD/certification/getEJBObject-setSessionContext
Pradeep Sashidhara
Greenhorn

Joined: May 21, 2007
Posts: 8
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
 
subject: Why can stateless ejbCreate() access EJBObject???