File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes ejbCreate() in Stateless session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "ejbCreate() in Stateless session bean" Watch "ejbCreate() in Stateless session bean" New topic

ejbCreate() in Stateless session bean

Nikhil Pendharkar
Ranch Hand

Joined: Sep 01, 2003
Posts: 44
Hi ,
In the home interface of Statless session bean we declare a create method having Return type as the Remote Interface . Then why the bean class of stateless session bean has ejbCreate() method returning void ?
Thanks ,
Magnus Stattin
Ranch Hand

Joined: Jun 05, 2003
Posts: 65
It is the container that is responible for returning the remote component interface to the client (the instance of the stub that implements the remote component interface). The bean does not have to be involved in that.
Hope it helps
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Nikhil, just to add on to what Magnus already indicated, here is how try to remember it...
The container callbacks only return what the container needs in order to complete its job, and only pass what the bean needs to complete its job. That is why the ejbCreate() signatures vary across the various enterprise bean types.
Stateless session beans and message-driven beans:
void ejbCreate() because the container doesn't need to know
anything else to identify the bean, and the
bean doesn't need to know anything else in
order to complete its creation. The container
doesn't care about identifying the bean via
a returned value, it'll just pull a bean out
of the pool at random when it needs one.
Stateful session beans:
void ejbCreate(args) because the bean may need initialization
parameters, but the container's job is done.
It is going to immediately give the instance
it just created to the EJBObject skeleton.
Entity beans:
FooPK ejbCreate(args) because the bean may (almost always does)
need initialization parameters, and the container
needs to know the primary key that was generated.
Different clients at different times will ask to
use this entity, and the only way the container
can find the right instance is via the PK that
was returned during creation (and probably stuffed
into a hashtable somewhere).
The last case is a little odd, because the signature has to accomodate both
BMP and CMP. CMP ejbCreate implementation returns null because the container figures out the PK from the virtual fields and the descriptor,
but BMP would return the actual PK value.

Reid - SCJP2 (April 2002)
I agree. Here's the link:
subject: ejbCreate() in Stateless session bean
It's not a secret anymore!