Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SessionContext and ejbCreate (for stateless session beans)

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) ??
 
X. Li
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sandeep vaid
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Mark Lybarger
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tonio Morelli
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic