This section describes the responsibilities of the container provider for handling exceptions. The EJB architecture specifies the container's behavior for the following exceptions:
EJB.12.3.1 Exceptions from an Enterprise Bean's Business MethodsBusiness methods are considered to be the methods defined in the enterprise bean's remote and home interface (including all their superinterfaces) and the following methods: ejbCreate(...) , ejbPostCreate(...) , ejbRemove() , and the ejbFind<METHOD> methods. Table EJB.12-1 specifies how the container must handle the exceptions thrown by the business methods for beans with container-managed transaction demarcation. The table specifies the container's action as a function of the condition under which the business method executes and the exception thrown by the business method. The table also illustrates the exception that the client will receive and how the client can recover from the exception. (Section EJB.12.4 describes the client's view of exceptions in detail.) Table EJB.12-2 specifies how the container must handle the exceptions thrown by the business methods for beans with bean-managed transaction demarcation. [3] The table specifies the container's action as a function of the condition under which the business method executes and the exception thrown by the business method. The table also illustrates the exception that the client will receive and how the client can recover from the exception. (Section EJB.12.4 describes the client's view of exceptions in detail.)
Table EJB.12-1. Handling of Exceptions Thrown by a Business Method of a Bean with Container-Managed Transaction Demarcation
Table EJB.12-2. Handling of Exceptions Thrown by a Business Method of a Session with Bean-Managed Transaction Demarcation
EJB.12.3.2 Exceptions from Container-Invoked CallbacksThis subsection specifies the container's handling of exceptions thrown from the container-invoked callbacks on the enterprise bean. It applies to the following callback methods:
The container must handle all exceptions or errors from these methods as follows :
EJB.12.3.3 javax.ejb.NoSuchEntityExceptionThe NoSuchEntityException is a subclass of EJBException . If it is thrown by a method of an entity bean class, the container must handle the exception using the rules for EJBException described in Sections EJB.12.3.1 and EJB.12.3.2. To give the client a better indication of the cause of the error, the container should throw the java.rmi.NoSuchObjectException to the client (which is a subclass of java.rmi.RemoteException ). EJB.12.3.4 Non-Existing Session ObjectIf a client makes a call to a session object that has been removed, the container should throw the java.rmi.NoSuchObjectException to the client (which is a subclass of java.rmi.RemoteException ). EJB.12.3.5 Exceptions from the Management of Container-Managed TransactionsThe container is responsible for starting and committing the container-managed transactions, as described in Section EJB.11.6.2. This subsection specifies how the container must deal with the exceptions that may be thrown by the transaction start and commit operations. If the container fails to start or commit a container-managed transaction, the container must throw the java.rmi.RemoteException to the client. However, the container should not throw the java.rmi.RemoteException if the container performs a transaction roll back because the instance has invoked the setRollbackOnly() method on its EJBContext object. In this case, the container must roll back the transaction and pass the business method result or the application exception thrown by the business method to the client. Note that some implementations of the container may retry a failed transaction transparently to the client and enterprise bean code. Such a container would throw the java.rmi.RemoteException after a number of unsuccessful tries . EJB.12.3.6 Release of ResourcesWhen the container discards an instance because of a system exception, the container should release all the resources held by the instance that were acquired through the resource factories declared in the enterprise bean environment (See Section EJB.14.4). Note While the container should release the connections to the resource managers that the instance acquired through the resource factories declared in the enterprise bean environment, the container cannot, in general, release "unmanaged" resources that the instance may have acquired through the JDK APIs. For example, if the instance has opened a TCP/IP connection, most container implementations will not be able to release the connection. The connection will be eventually released by the JVM garbage collector mechanism. EJB.12.3.7 Support for Deprecated Use of java.rmi.RemoteExceptionThe EJB 1.0 specification allowed the business methods, ejbCreate , ejbPostCreate , ejbFind<METHOD> , ejbRemove , and the container-invoked callbacks (i.e., the methods defined in the EntityBean , SessionBean , and SessionSynchronization inter-faces) implemented in the enterprise bean class to use the java.rmi.RemoteException to report non-application exceptions to the container. This use of the java.rmi.RemoteException is deprecated in EJB 1.1 ”enterprise beans written for the EJB 1.1 specification should use the javax.ejb.EJBException instead. The EJB 1.1 specification requires that a container support the deprecated use of the java.rmi.RemoteException . The container should treat the java.rmi.RemoteException thrown by an enterprise bean method in the same way as it is specified for the javax.ejb.EJBException . Note The use of the java.rmi.RemoteException is deprecated only in the above-mentioned methods. The methods of the remote and home interface still must use the java.rmi.RemoteException as required by the EJB specification. |