Exceptions and Transactions
Exceptions have a large impact on the outcome of transactions.
Application Exceptions Versus System Exceptions
System exceptions represent unknown internal errors. The EJB container throws system exceptions when it encounters an internal application server failure. Business logic can throw system exceptions when it wants to abort the business process. Application exceptions are exceptions that are part of your business logic. They denote a strongly typed definition of a specific business problem or failure but do not necessarily abort or roll back the business process.
System exceptions
System exceptions include java.lang.RuntimeException
and its
subclasses. EJB
Exception
is a
subclass of RuntimeException
, so it is considered a
system exception. System exceptions also include java.rmi.RemoteException
and its subclasses.
The Runtime
Exception
and
RemoteException
subclasses
differ in that they can be turned into application exceptions using
the @javax.ejb.ApplicationException
annotation. This annotation is discussed later in this chapter.
System exceptions always cause a transaction to roll back when
they are thrown from an enterprise bean method. Any RuntimeException
not annotated with @Application
Exception
that
is thrown within a business method (for instance, EJBException
, Null
PointerException
, IndexOutOfBoundsException
, and so
on) is handled by the container automatically and results in
a transaction rollback. In Java, RuntimeException
types do not need to ...
Get Enterprise JavaBeans 3.1, 6th 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.