• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFEJB page 282

 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the Stateless session beans REMOVE:
"Client will get an exception if he tries to use the EJB object reference after removing the bean".

Is it right? I have in the Client:
------------------------------------------------------
1. Advice advisor = home.create();
2. System.out.println(advisor.getTheMessage());
3. advisor.remove();
4. System.out.println(advisor.getTheMessage());
------------------------------------------------------
... and in 4. I have the message and NOT the Exception.
 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You CAN use the component interface to remove a session bean.
For stateless session bean, when you invoke remove() the container doesn't necessarily invoke the corresponding ejbRemove() method on the bean class.

Andrea
 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is all right.
But the question is:

WHY

"Client will get an exception if he tries to use the EJB object reference after removing the bean" ???

Thanks.
 
Karin Paola Illuminate
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use a stateful session bean remove, I will get an advice and an exception. If I use a stateless session bean remove, I will get two times an advice.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Veri Strora:


"Client will get an exception if he tries to use the EJB object reference after removing the bean"


Even though the Container does not *kill* a stateless bean (or invoke the bean's ejbRemove() as a direct result) when the client removes a bean (through either the component or home interface of a Remote bean, or the component interface of a local bean), the Container DOES care that the client said "I'm done with this bean." The Container is free at that point to do whatever it wants to make the client's EJBObject reference invalid, for example. This does not mean that all Containers will do this, but according to the spec, the client is not to try to use a bean's component interface *after* he has told the Container that he is finished with that bean (by invoking remove()).

Does that make sense?

So think of it as the client saying, "I'm done with this bean." and the Container's response is, "I'm not going to kill the bean; I'll just send it back in the pool. But YOU can't use it again!"

cheers,
Kathy
 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much Kathy, and congratulations for the excellent Book.

I understand You very well, but the confusion comes from where I'prove the example and expected an exception ("Client WILL get an exception if...").

I know that my english isn't so good.

Thanks again, Veri.

P.S. I'm waiting Your book about the patterns...
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah... I see what you're asking. I believe in that case the Container is simply *not* following the spec. In other words, you *should* have gotten an exception, but the Container just let you "get away with it".

This is difficult when you're learning--because you cannot judge the specification just by testing (in some cases, even using the reference implementation). If there is a difference between what the Container does and what the spec says, always assume the spec is how it is *supposed* to work, even if you see something different by the server.

cheers,
Kathy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic