ExceptionsAlthough exception handling is covered in detail in Chapter 13, basic exception information is provided here for your convenience. Figure A.2 shows you a UML diagram of the EJB exceptions and their relationships. Figure A.2. A UML diagram representing the EJB exception hierarchy.
Note All the EJB exceptions declare a no-argument constructor and one that accepts a String message. AccessLocalExceptionAn AccessLocalException is thrown to indicate that the caller does not have permission to call the method. This exception is thrown to local clients . CreateExceptionThe CreateException exception must be included in the throws clauses of all create methods defined in an enterprise bean's component interface. DuplicateKeyExceptionThe DuplicateKeyException exception is thrown if an entity EJB object cannot be created because an object with the same key already exists. EJBExceptionThe EJBException exception is thrown by an enterprise bean instance to its container to report that the invoked business method or callback method could not be completed because of an unexpected error. Note EJBException also declares a constructor that takes an Exception as the single argument. With this constructor, you can declare an EJBException that wraps another exception. FinderExceptionThe FinderException exception must be included in the throws clause of every find method of an entity bean's home interface. NoSuchEntityExceptionThe NoSuchEntityException exception is thrown by an enterprise bean instance to its container to report that the invoked business method or callback method could not be completed because the underlying entity was removed from the database. This exception can be thrown by the bean class methods that implement the business methods defined in the bean's remote interface and also by the ejbLoad and ejbStore methods. Note NoSuchEntityException also declares a constructor that takes an Exception as the single argument. With this constructor, you can create a NoSuchEntityException that wraps another exception. NoSuchObjectLocalExceptionA NoSuchObjectLocalException is thrown if an attempt is made to invoke a method on a local object that no longer exists. ObjectNotFoundExceptionThe ObjectNotFoundException exception is thrown by a single object finder method to indicate that the specified EJB object does not exist. RemoveExceptionThe RemoveException exception is thrown at an attempt to remove an EJB object when the enterprise bean or the container does not allow the EJB object to be removed. TransactionRequiredLocalExceptionThis exception indicates that a request carried a null transaction context, but the target object requires an activate transaction. TransactionRolledbackLocalExceptionThis exception indicates that the transaction associated with processing of the request has been rolled back, or marked to roll back. Thus, the requested operation either could not be performed or was not performed because further computation on behalf of the transaction is not necessary. |