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

Sun Microsystems Inc.

Entity Bean Component Contract for Bean Managed PersistenceEnterprise JavaBeans 2.0, Public Draft Overview of Bean Managed

11.1.9 Standard application exceptions for Entities

The EJB specification defines the following standard application exceptions:

javax.ejb.CreateException

javax.ejb.DuplicateKeyException

javax.ejb.FinderException

javax.ejb.ObjectNotFoundException

javax.ejb.RemoveException

11.1.9.1CreateException

From the client’s perspective, a CreateException (or a subclass of CreateException) indicates that an application level error occurred during the create<METHOD>(...) operation. If a client receives this exception, the client does not know, in general, whether the entity object was created but not fully initialized, or not created at all. Also, the client does not know whether or not the transaction has been marked for rollback. (However, the client may determine the transaction status using the

UserTransaction interface.)

The Bean Provider throws the CreateException (or subclass of CreateException) from the ejbCreate<METHOD>(...) and ejbPostCreate<METHOD>(...) methods to indicate an application-level error from the create or initialization operation. Optionally, the Bean Provider may mark the transaction for rollback before throwing this exception.

The Bean Provider is encouraged to mark the transaction for rollback only if data integrity would be lost if the transaction were committed by the client. Typically, when a CreateException is thrown, it leaves the database in a consistent state, allowing the client to recover. For example, ejbCreate may throw the CreateException to indicate that the some of the arguments to the create<METHOD>(...) methods are invalid.

The Container treats the CreateException as any other application exception. See Section 17.3.

11.1.9.2 DuplicateKeyException

The DuplicateKeyException is a subclass of CreateException. It is thrown by the ejbCreate<METHOD>(...) methods to indicate to the client that the entity object cannot be created because an entity object with the same key already exists. The unique key causing the violation may be the primary key, or another key defined in the underlying database.

Normally, the Bean Provider should not mark the transaction for rollback before throwing the exception.

When the client receives the DuplicateKeyException, the client knows that the entity was not created, and that the client’s transaction has not typically been marked for rollback.

5/31/00

234