Common system exceptions
IllegalStateException
The Container throws this to a bean if the bean calls a method on its context that isn’t allowed at that time. For example, a session bean can’t ask its context for a reference to its EJB object while in the setSessionContext() method. It’s too early. A bean can also get an IllegalStateException if it calls a transaction method like setRollbackOnly() or getRollbackOnly(), when there’s no transaction!
EJBException
The bean throws this to tell the Container a system exception has occurred (which forces the Container to rollback the transaction, log the exception, kill the bean, and give a local client the EJBException and a remote client a RemoteException). But the Container can also throw this for a variety of other reasons we’ll look at in a minute.
NoSuchObjectLocalException
This exception is kind of a local companion to java.rmi.NoSuchObjectException. The Container throws it to the client when the client invokes a method on a local home or component interface, but there’s no underlying bean to support the object. This can happen, for example, if the bean has already been removed (either through a previous client call to remove(), or because the Container killed the bean due to an exception, stateful bean timeout, or to reduce the size of the pool).
NoSuchEntityException
You probably won’t see or use this exception much, especially with CMP, but it’s for you to throw from your bean code when you want to tell the Container that the entity ...
Get Head First EJB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.