Handling errors in a transaction

When an error occurs during the execution of a transaction, the transaction may or may not need to be rolled back. It all depends on the nature of the error. Exceptions are classified as either checked exceptions, a java.lang.Exception derived class, or unchecked exceptions, a java.lang.RuntimeException derived class.

If an unchecked exception is thrown, a transaction is automatically rolled back. For checked exceptions, the UserTransaction's rollback method or the SessionContext's setRollbackOnly method are used to explicitly force a rollback.

Checked exceptions are considered to be application exceptions while unchecked exceptions are system exceptions. However, an application can declare its own unique exceptions ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.