Java Reference
In-Depth Information
Using the TransactionInterceptor is the most flexible approach since it allows
you to specify the isolation level on a per-transaction basis, which is a common
requirement. The other two options are useful only if you want to use the serializ-
able isolation level for all transactions.
Signaling concurrent update failures
When Hibernate detects a concurrency failure, it throws one of the subclasses of
HibernateException that are shown in figure 12.8. If it's an optimistic locking fail-
ure, Hibernate throws a StaleObjectStateException , which extends StaleState-
Exception . Serializable and pessimistic locking failures cause JDBC to throw a
SQLException , which Hibernate maps to a subclass of JDBCException , which con-
tains the SQLException .
The HibernateTemplate that calls the Hibernate API automatically maps the
HibernateException s to a Spring DataAccessException . It maps the StaleObject-
StateException to a Spring OptimisticLockingFailureException . A Hibernate-
Template maps a JDBCException to a DataAccessException by mapping the
SQLException that it contains using the same SQLExceptionTranslator -based mech-
anism used by Spring's JDBC and i BATIS classes. Consequently, the application must
use the MyOracleSQLExceptionTranslator , which was described in section 12.2.5, to
map a SQLException to the corresponding data concurrency exception.
In order to do this, you must configure the HibernateTemplate with a MyOra-
cleSQLExceptionTranslator by setting its jdbcExceptionTranslator property:
Hibernate
Exception
Stale
StateException
SQLException
JDBCException
...
StaleObject
StateException
...
Figure 12.8
Hibernate exceptions that are thrown when a concurrency failure occurs.
 
 
 
 
 
 
Search WWH ::




Custom Search