Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container's action, and the client's view.

[Note]

Exceptions from a Session Bean's Business Interface Methods

Table below specifies how the container must handle the exceptions thrown by the methods of the business interface for beans with container-managed transaction (CMT) demarcation, including the exceptions thrown by business method interceptor methods which intercept the invocation of business methods. The table specifies the container's action as a function of the condition under which the business interface method executes and the exception thrown by the method. The table also illustrates the exception that the client will receive and how the client can recover from the exception.

Table 10.1.  Handling of Exceptions Thrown by a Business Interface Method of a Bean with Container-Managed Transaction Demarcation

Method conditionMethod exceptionContainer's actionClient's view

Bean method runs in the context of the caller's transaction.

The caller can be another enterprise bean or an arbitrary client program.

This case may happen with Required, Mandatory, and Supports attributes.

Application Exception

Re-throw Application Exception.

Mark the transaction for rollback if the application exception is specified as causing rollback.

Receives Application Exception.

Can attempt to continue computation in the transaction, and eventually commit the transaction unless the application exception is specified as causing rollback (the commit would fail if the instance called setRollbackOnly).

all other exceptions

Log the exception or error (so that the System Administrator is alerted of the problem).

Mark the transaction for rollback.

Discard instance (so that the container must not invoke any business methods or container callbacks on the instance).

Throw javax.ejb.EJBTransactionRolledbackException to client. If the business interface is a remote business interface that extends java.rmi.Remote, the javax.transaction.TransactionRolledbackException is thrown to the client, which will receive this exception.

Receives javax.ejb.EJBTransactionRolledbackException.

Continuing transaction is fruitless.

Bean method runs in the context of a transaction that the container started immediately before dispatching the business method.

This case may happen with Required and RequiresNew attributes.

Application Exception

If the instance called setRollbackOnly(), then rollback the transaction, and re-throw Application Exception.

Mark the transaction for rollback if the application exception is specified as causing rollback, and then re-throw Application Exception.

Otherwise, attempt to commit the transaction, and then re-throw Application Exception.

Receives Application Exception.

If the client executes in a transaction, the client's transaction is NOT marked for rollback, and client can continue its work.

all other exceptions

Log the exception or error.

Rollback the container-started transaction.

Discard instance.

Throw EJBException to client. If the business interface is a remote business interface that extends java.rmi.Remote, the java.rmi.RemoteException is thrown to the client, which will receive this exception.

Receives EJBException.

If the client executes in a transaction, the client's transaction may or may not be marked for rollback.

Bean method runs with an unspecified transaction context.

This case may happen with with the NotSupported, Never, and Supports attributes.

Application Exception

Re-throw Application Exception.

Receives Application Exception.

If the client executes in a transaction, the client's transaction is NOT marked for rollback, and client can continue its work.

all other exceptions

Log the exception or error.

Discard instance.

Throw EJBException to client. If the business interface is a remote business interface that extends java.rmi.Remote, the java.rmi.RemoteException is thrown to the client, which will receive this exception.

Receives EJBException.

If the client executes in a transaction, the client's transaction may OR may not be marked for rollback.

Table below specifies how the container must handle the exceptions thrown by the methods of the business interface for beans with bean-managed transaction (BMT) demarcation, including the exceptions thrown by business method interceptor methods which intercept the invocation of business methods. The table specifies the container's action as a function of the condition under which the business interface method executes and the exception thrown by the method. The table also illustrates the exception that the client will receive and how the client can recover from the exception.

Table 10.2.  Handling of Exceptions Thrown by a Business Interface Method of a Session Bean with Bean-Managed Transaction Demarcation

Bean method conditionBean method exceptionContainer actionClient receives

Bean is stateful or stateless session.

Application Exception

Re-throw Application Exception.

Receives Application Exception.

all other exceptions

Log the exception or error.

Mark for rollback a transaction that has been started, but not yet completed, by the instance.

Discard instance.

Throw EJBException to client. If the business interface is a remote business interface that extends java.rmi.Remote, the java.rmi.RemoteException is thrown to the client, which will receive this exception.

Receives EJBException.

Exceptions from Message-Driven Bean Message Listener Methods

Table below specifies how the container must handle the exceptions thrown by a message listener method of a message-driven bean with container-managed transaction (CMT) demarcation, including the exceptions thrown by business method interceptor methods which intercept the invocation of message listener methods. The table specifies the container's action as a function of the condition under which the method executes and the exception thrown by the method.

Table 10.3.  Handling of Exceptions Thrown by a Message Listener Method of a Message-Driven Bean with Container-Managed Transaction Demarcation

Method conditionMethod exceptionContainer's action

Bean method runs in the context of a transaction that the container started immediately before dispatching the method.

This case happens with the Required attribute.

Application Exception

Mark the transaction for rollback if the application exception is specified as causing rollback.

If the instance called setRollbackOnly, rollback the transaction and re-throw Application Exception to resource adapter.

Otherwise, attempt to commit the transaction unless the application exception is specified as causing rollback and re-throw Application Exception to resource adapter.

system exceptions

Log the exception or error (so that the System Administrator is alerted of the problem).

Rollback the container-started transaction.

Discard instance (so that the container must not invoke any methods on the instance).

Throw EJBException that wraps the original exception to resource adapter.

Bean method runs with an unspecified transaction context.

This case happens with the NotSupported attribute.

Application Exception

Re-throw Application Exception to resource adapter.

system exceptions

Log the exception or error.

Discard instance.

Throw EJBException that wraps the original exception to resource adapter.

Table below specifies how the container must handle the exceptions thrown by a message listener method of a message-driven bean with bean-managed transaction (BMT) demarcation. The table specifies the container's action as a function of the condition under which the method executes and the exception thrown by the method.

Table 10.4.  Handling of Exceptions Thrown by a Message Listener Method of a Message-Driven Bean with Bean-Managed Transaction Demarcation

Bean method conditionBean method exceptionContainer action

Bean is message-driven bean

Application Exception

Re-throw Application Exception to resource adapter.

system exceptions

Log the exception or error.

Mark for rollback a transaction that has been started, but not yet completed, by the instance.

Discard instance.

Throw EJBException that wraps the original exception to resource adapter.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine