Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc.

Exception handling

Enterprise JavaBeans 2.0, Public Draft

Container Provider responsibilities

Table 15 specifies how the Container must handle the exceptions thrown by the onMessage, ejbCreate, and ejbRemove methods for message-driven beans with bean-managed transaction demarcation. The table specifies the Container’s action as a function of the condition under which the method executes and the exception thrown by method.

Table 15

Handling of exceptions thrown by a method of a message-driven bean with bean-managed transaction

 

demarcation.

 

 

 

 

 

 

 

 

 

Bean method condition

Bean method exception

Container action

 

 

 

 

 

 

 

 

 

 

 

 

Bean is message-driven

system exceptions

Log the exception or

 

 

bean

 

error.

 

 

 

 

Mark for rollback a

 

 

 

 

transaction that has been

 

 

 

 

started, but not yet com-

 

 

 

 

pleted, by the instance.

 

 

 

 

Discard instance.

 

 

 

 

 

17.3.3 Exceptions from container-invoked callbacks

This subsection specifies the Container’s handling of exceptions thrown from the container-invoked callbacks on the enterprise bean. This subsection applies to the following callback methods:

The ejbActivate(), ejbLoad(), ejbPassivate(), ejbStore(), setEntityContext(EntityContext), and unsetEntityContext() methods of the EntityBean interface.

The ejbActivate(), ejbPassivate(), and setSessionContext(SessionContext) methods of the SessionBean interface.

The setMessageDrivenContext(MessageDrivenContext) method of the MessageDrivenBean interface.

The afterBegin(), beforeCompletion() and afterCompletion(boolean) methods of the SessionSynchronization interface.

The Container must handle all exceptions or errors from these methods as follows:

Log the exception or error to bring the problem to the attention of the System Administrator.

If the instance is in a transaction, mark the transaction for rollback.

Discard the instance (i.e. the Container must not invoke any business methods or container callbacks on the instance).

5/31/00

348

Sun Microsystems Inc

Container Provider responsibilities

Enterprise JavaBeans 2.0, Public Draft

Exception handling

If the exception or error happened during the processing of a client invoked method, throw the java.rmi.RemoteException to the client. If the instance executed in the client’s transaction, the Container should throw the javax.transaction.TransactionRolledBackException because it provides more information to the client. (The client knows that it is fruitless to continue the transaction.)

17.3.4 javax.ejb.NoSuchEntityException

The 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 17.3.1, 17.3.2, and 17.3.3.

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

17.3.5 Non-existing session object

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

17.3.6 Exceptions from the management of container-managed transactions

The container is responsible for starting and committing the container-managed transactions, as described in Subsection 16.7.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. In the case where the Container fails to start or commit a container-managed transaction on behalf of a message-driven bean, the Container must throw and log the javax.ejb.EJBException.

However, the Container should not throw the java.rmi.RemoteException if the Container performs a transaction rollback because the instance has invoked the setRollbackOnly() method on its EJBContext object. In this case, the Container must rollback 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.

349

5/31/00