Java Reference
In-Depth Information
JDOException
Throwable getCause()
JDOFatalException
...
JDOFatalDataStore
Exception
JDOOptimistic
VerificationException
Figure 12.7
Part of the
JDOException
class hierarchy
When an optimistic locking failure occurs, the
JDO
implementations throws a
JDOOptimisticVerificationException
. The
JDO
specification does not describe
which subclass of
JDOException
the
JDO
implementation will throw to signal pessi-
mistic locking and serializable transaction failures. However, it's possible that the
JDOException
will contain the underlying
SQLException
, which can be accessed by
calling
JDOException.getCause()
. For more information about how errors are
reported, consult your
JDO
implementation's documentation.
The
JdoTemplate
maps the
JDOOptimisticVerificationException
to a Spring
OptimisticLockingFailureException
. In addition, if the
JDOException
contains a
SQLException
, the
JdoTemplate
will convert it to a data access exception using the
exception mapping mechanism we saw in section 12.2.5. We can even plug in our
own custom
SQLExceptionTranslator
. As a result, it's possible that the
JdoTem-
plate
will report pessimistic locking and serializable transaction errors correctly.
Except for this relatively minor issue and potential problem with using optimistic
locking and pessimistic locking in the same application, it is relatively easy to use
all three concurrency mechanisms in a
JDO
application. Next we'll examine how
to use optimistic locking, pessimistic locking, and serializable transactions in a
Hibernate application.
12.3.3
Handling concurrent updates with Hibernate
Hibernate, like
JDO
, also supports optimistic locking, pessimistic locking, and seri-
alizable transactions. In this section, we use the business logic for the Send Orders
Search WWH ::
Custom Search