• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing EJBObject reference in ejbCreate() and ejbRemove()

 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
Pg 228 from HeadFirst EJB states that it is possible to get a reference to the EJBObject from a stateless bean's ejbCreate and ejbRemove methods. I am having a hard time understanding it.
Since the creation and removal of stateless bean is container controlled and the client is only linked to the bean while running a business method. Since ejbCreate and ejbRemove are not business methods, bean is not linked to an EJBObject. So in this case then how can it return a reference?
Thanks
Sudhir
 
David Harrigan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, but it is!
ejbCreate is called whenever a bean is created by the client, and at that point, the bean is "temporarily" connected to the client (via the EJBObject), thus it is permissible for the bean, in ejbCreate, to call getEJBObject. See the OID on page 92 of the spec.
The client can indeed call remove on a stateless session bean (see the OID on page 93 of the spec), thus it can call getEJBObject in ejbRemove. The container just moves the bean back into the pool.
Hope this helps.
-=david=-
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ejbCreate is called whenever a bean is created by the client

The container creates the SLSB and not the client.
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That helps. Thanks
 
David Harrigan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradeep Bhat,
Yes, I wondered on that - yes, the container creates all beans, but, the client is still allowed to call "create" on the home for the bean - it's just that the container will do the creation for them. That's what I meant ;-)
-=david=-
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
David, reading your multiple comments from this morning, I really wonder if you are preparing to pass SCBCD in 3 days...
Impressive !
Sudhir, if you compare the stateless version of ejbCreate() on p.228 of HFE with the stateful one (p.196), the *only* difference is that stateless session beans have no access to security information about the client.
But it's quite logical, isn't it ?
Stateless session beans are *pre-created* by the Container, and then pooled (to be later called by clients), meaning that when they are created there is *no client* yet (or no relation with them anyway).
While stateful session beans are only created as a result of a client's create*() call on their home interface. As a result, when ejbCreate*() is called, the client is well known, hence the security stuff can be tested.
Regards,
Phil.
[ January 06, 2004: Message edited by: Philippe Maquet ]
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Philip I agree with your reason but when u say "are created there is *no client* yet" So if no client exist then how can an EJBObject exist? Isn't EJBObject linked to a client. so if EJBObject does not exist then how can we call for a reference to EJBObject during creation.
Also does the Container call the ejbRemove method when it removes a stateless bean from a pool due to lack of resources (assume there are currently no clients which means no EJBObjects exist)? So in that case if the ejbRemove contains a call for EJBObject then what happens?
Sudhir
[ January 06, 2004: Message edited by: Sudhir Sudhir ]
[ January 06, 2004: Message edited by: Sudhir Sudhir ]
 
Philippe Maquet
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sudhir,
Sorry, I finally got it : answer is here.
Best,
Phil.
 
Sudhir V
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it makes sense. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic