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

"NoSuchEntityException" vs "NoSuchObjectException" -- HFBook ,p.563

 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

In HFBook ,p.563, #2:

Which scenario will cause a java.rmi.NoSuchObjectException to be thrown ? (Choose all that apply)


A.
A remote client invokes a method on a stateful session bean which has been removed.

B.
A remote client invokes a method on an entity bean which has been removed.

Answer is A & B.

I agree the ans is A. But I don't understand by B is also correct.
As far as I know:

1. entity bean don't have remote interface, what's the "remote client invokes a method on an entity bean" means ? Is it RemoteClient --> Session Bean --(locally called)--> entity bean.

2. Refer to ans B, why "NoSuchEntityException" will not be thrown ? (since during the method execution, the entity bean may be removed by admin way, refer to HFBook P.552, point 4).

3. Refer to entity bean, what's the different between "NoSuchEntityException" and "NoSuchObjectException" ?
I. NoSuchObjectException - A stub call a corrupted / no longer invalid EJBObject.
II. NoSuchEntityException - Called Entity is no longer in the database.

Seems point II can be the reason of point I, I can't see the difference between 2.

thanks !
 
sawan parihar
Ranch Hand
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#########################################################################
As far as I know:

1. entity bean don't have remote interface, what's the "remote client invokes a method on an entity bean" means ? Is it RemoteClient --> Session Bean --(locally called)--> entity bean.

#########################################################################

First of all entity beans can have remote interfaces. If the session bean or the entity bean is removed and the client tries to invoke a method then
NoSuchObjectException will be thrown.

NoSuchEntityException will be thrown when the entity is not there in the persistent storage. Suppose you have a database with the table having customer information and someone using database admin tool deleted the entry of a specific customer for which you are calling the method on the entity bean. In this case the NoSuchEntityException will be thorwn.

Hope that helps
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx sawan.

Let me clarify if my concept is correct:

NoSuchEntityException will be thrown when the entity is not there in the persistent storage.


If I change that statement to:
1.
A remote client invokes a method on an entity bean which *its persistent storage has been deleted by other means*.
--> Is it possible the client recieve "NoSuchObjectException" (Since "NoSuchEntityException" is for local client only) ?
In this case, the bean should throw "NoSuchEntityException", the container catch it and rethrow as "NoSuchObjectException" to the client, am I correct ?

2.
A *LOCAL* client invokes a method on an entity bean which *its persistent storage has been deleted by other means*.
--> Will the local client recieve "NoSuchObjectLocalException" or "NoSuchEntityException" ?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vince Hon:

In this case [for Remote], the bean should throw "NoSuchEntityException", the container catch it and rethrow as "NoSuchObjectException" to the client, am I correct ?

Yes.

2.
A *LOCAL* client invokes a method on an entity bean which *its persistent storage has been deleted by other means*.
--> Will the local client recieve "NoSuchObjectLocalException" or "NoSuchEntityException" ?

The client receives NoSuchObjectLocalException.

See section 18.3.4 on page 379 of the spec.
[ April 14, 2005: Message edited by: Marc Peabody ]
 
Chengwei Lee
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Is it possible the client recieve "NoSuchObjectException" (Since "NoSuchEntityException" is for local client only) ?


Where did you get that idea that NoSuchEntityException is meant for local client only? It is actually an exception thrown by the bean to inform the container that the entity is missing. (Refer to HFEJB, page 552)


A *LOCAL* client invokes a method on an entity bean which *its persistent storage has been deleted by other means*.
--> Will the local client recieve "NoSuchObjectLocalException" or "NoSuchEntityException" ?


The client doesn't get to "see" the NoSuchEntityException. Its thrown by the bean to the container. The container throws NoSuchObject(Local)Exception to the client.
 
Vince Hon
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chengwai and Marc !

I have a clear concept now.
The reason of I get confused because I misunderstood the exception throwing pathway:
Bean --> Container (NoSuchEntityException)
and
Container --> Client (NoSuchObject(Local)Exception)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic