Originally posted by Edy Yu:
I assume the only valid create method in the hoem interface of the stateless session bean is create().
The method createABC() won't be allowed for stateless session bean.
Can anybody explain why? The createABC() method does not take any parameter. This means my bean can be stateless ...
How a particular create method on a home interface relates to a corresponding ejbCreate method on the bean implementation differs according to the kind of bean. Basically the reason has to do with the differences in the lifecycle of the two types of session bean.
- Stateless session bean
Client calls create() really to get a stub.
Doesn't directly cause ejbCreate() to be called
(container creates a bean instance as needed)
- Stateful session bean
Client calls a particular createXXX() to
create a stub and an instance configured
according to the corresponding ejbCreateXXX().
When you have an EJBObject/EJBLocalObject stub for
a stateless bean, you don't have a specific session
bean instance associated with your stub. The container
waits until you ask it to do something and temporarily
assigns a bean instance to handle your request. If
all instances are equal, there is no point (and no
opportunity) for a client-specific way of creating the
bean. Thus only one ejbCreate() method.
When you have an EJBObject/EJBLocalObject stub for
a stateful bean, you get a specific instance assigned
to you for as long as you need it, because you'll
potentially be changing the state of that bean.
The client has the added bonus of being able to tell
the container to use a specific ejbCreate() method
to initialize the bean the way the client wants.
That doesn't hurt any other client - they each had
their own opportunity to initialize their own
private instance of their stateful session bean.