Hi Amol,
I got back home and got hold of the book
You're right when you say
... container is free to choose if it wants to give more specific
exception. But I thought it was talking in context of exceptions
like DuplicateKeyException which is a subclass of CreateException
and ObjectNotFoundException which is subclass of FinderException.
(see HF EJB p.550)
So what I've said in the previous post is not correct

. Throwing
the NoSuchObjectException is a requirement of the spec.
In the EJB specs (18.4.2.3) it says:
The java.rmi.NoSuchObjectException is a subclass of the java.rmi.RemoteException.
It is thrown to the client if a remote business method
cannot complete because the EJB object no longer exists.
and
When the client calls remove on the home or component interface to remove
the session object, the container issues ejbRemove() on the bean instance.
This ends the life of the session bean instance and the associated session
object. Any subsequent attempt by its client to invoke the session object
causes the java.rmi.NoSuchObjectException to be thrown if the client is a
remote client, or the javax.ejb.NoSuchObjectLocalException if the client is
a local client. (The java.rmi.NoSuchObjectException is a subclass of the
java.rmi.RemoteException; the javax.ejb.NoSuchObjectLocalException is a
subclass of the javax.ejb.EJBException). The ejbRemove() method cannot be
called when the instance is participating in a transaction. An attempt to
remove a session object while the object is in a transaction will cause the
container to throw the javax.ejb.RemoveException to the client. Note that a
container can also invoke the ejbRemove() method on the instance without a
client call to remove the session object after the lifetime of the EJBobject has expired.
(see EJB spec 7.6.0)
I think that when HF EJB says you will get a RemoteException or a
EJBException is technically correct, since these are superclasses
of the more specific exceptions NoSuchObjectException and
NoSuchObjectLocalException. But according to the specs I'd say
the HF statement is not precise enough
What do you think?
Gian
[ March 10, 2005: Message edited by: Gian Franco Casula ]