Exceptions and transactions
EJB specifies well-defined rules that let us control whether an exception immediately marks the current transaction for rollback when it is thrown by a business method of the bean:
system exceptions
always cause a transaction rollback,
application exceptions
do not cause a rollback by default, but they do if @ApplicationException(rollback=true)
is specified. (An application exception is any checked exception, or any unchecked exception annotated @ApplicationException
. A system exception is any unchecked exception without an @ApplicationException
annotation.)
Note that there is a difference between marking a transaction for rollback, and actually rolling it back. The exception rules say that the transaction should be marked rollback only, but it may still be active after the exception is thrown.
Seam applies the EJB 3.0 exception rollback rules also to Seam JavaBean components.
But these rules only apply in the Seam component layer. What about an exception that is uncaught and propagates out of the Seam component layer, and out of the JSF layer? Well, it is always wrong to leave a dangling transaction open, so Seam rolls back any active transaction when an exception occurs and is uncaught in the Seam component layer.