EJB 1.0: Exceptions and Transactions

In EJB 1.0, the impact of exceptions on transactions largely depends on who initiates the transaction. A transaction that is started automatically when a bean method is invoked is a container-initiated transaction. Specifying the TX_REQUIRES_NEW transaction attribute, for example, always results in a container-initiated transaction. A TX_REQUIRED method invoked by a non-transactional client also results in a container-initiated transaction. A transaction that is started explicitly using JTA (on the client or in a TX_BEAN_MANAGED bean) is not a container-initiated transaction.

With container-initiated transactions, any exception thrown during a transaction can cause the transaction to roll back. The impact of an exception thrown during a transaction depends on the type of exception (checked or unchecked) and the transaction attribute of the bean method throwing the exception. This section examines the different combinations of exceptions (checked or unchecked) and transaction attributes and their combined affect on transactional outcomes.

Container-Initiated Transactions

Any exception (application exception, unchecked exception, or RemoteException) not handled within the scope of the container-initiated transaction causes the container to roll back the entire transaction.

Note

An exception that is not handled within the scope of container-initiated transaction is an exception that is propagated, through the call stack, beyond the bean method ...

Get Enterprise JavaBeans, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.