The five standard EJB application exceptions

The javax.ejb package has five standard application exceptions used by the EJB container, but you can use them as well, either directly or as superclasses to your own custom exceptions.

image with no caption
  1. CreateException

    The Container throws this from, you guessed it, a create method, if something goes wrong during creation. This includes scenarios in which the bean code throws CreateException itself, while running a create method. (Although if the bean’s gonna throw it, the bean’s gotta declare it in the bean class, not just the home interface)

  2. DuplicateKeyException

    The Container throws this to the client from an entity bean create method (see how it’s a subclass of CreateException?) if the business logic related to the create asks the Container to insert a new entity using a primary key that has already been assigned to another entity.

  3. FinderException

    The Container throws this to the client from an entity bean’s finder method, to tell the client that something went wrong during the finder. The bean might have thrown it (BMP beans only), but for CMP beans, only the Container can throw this method.

  4. ObjectNotFoundException

    The Container throws this to the client ONLY during single-entity finder methods, when there’s no entity in the database matching the primary key parameter of the finder method.

  5. RemoveException

    The Container throws this to the client from a session ...

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.