O'Reilly logo

Head First EJB by Bert Bates, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Common system exceptions

  1. 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!

  2. 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.

  3. 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).

  4. 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required