For stateless session beans' ejbCreate method, we can use SessionContext to access EJB Object. This is written in spec and HF EJB. But I don't know why ? stateless session beans are created separately from any client invocation. So when ejbCreate is called, there can be no client yet, and EJB Object is only created when a client calls "create" on the Home interface to let container create a EJB Object. So, when "ejbCreate" is called how can you know which EJB Object the bean is associated with (there can be no EJB Object yet) ??
I think we should try to understand create() for stateless bean in this way: Bean is created and pooled by container, while create() give you a way to get EJB object. It's not to create a bean, but an EJB object.
Container calls the ejbCreate() when it needes to create new bean instance in the beans' pool at server so and this is Independent to the client invaocation of create(), so How the container can create the client's EJBObject when there is not clinet call for create(). Moreover the creation of the EJBObject need some information of the clinet hence it can not be independent of client call of create().
my understanding is that there may only be one EJBObject per stateless session bean deployed to the container. the construction of an EJBObject isn't tied to a client's create() call. client's create only returns a reference that'll let them call methods on the slsb. client information isn't needed by the slsb (container) until the business method is executed.
According to the Head First book, the EJBObject is created per client (p. 224), and the bean is not connected to the EJBObject until a business call on the stateless session bean is made, so I must say that I'm also perplexed - accordingly, there can be no way to get a reference to the EJBObject in create() or remove(). Either the HF book is in error about EJBObjects per client, or it's wrong about getting a reference to the EJBObject in the create() or remove(). I'd really like a definitive answer on which is correct!