@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2012 the original author or authors .
* Copyright 2002 - 2013 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -26,8 +26,10 @@ import org.hibernate.NonUniqueObjectException;
@@ -26,8 +26,10 @@ import org.hibernate.NonUniqueObjectException;
import org.hibernate.NonUniqueResultException ;
import org.hibernate.ObjectDeletedException ;
import org.hibernate.PersistentObjectException ;
import org.hibernate.PessimisticLockException ;
import org.hibernate.PropertyValueException ;
import org.hibernate.QueryException ;
import org.hibernate.QueryTimeoutException ;
import org.hibernate.Session ;
import org.hibernate.SessionFactory ;
import org.hibernate.StaleObjectStateException ;
@ -35,6 +37,8 @@ import org.hibernate.StaleStateException;
@@ -35,6 +37,8 @@ import org.hibernate.StaleStateException;
import org.hibernate.TransientObjectException ;
import org.hibernate.UnresolvableObjectException ;
import org.hibernate.WrongClassException ;
import org.hibernate.dialect.lock.OptimisticEntityLockException ;
import org.hibernate.dialect.lock.PessimisticEntityLockException ;
import org.hibernate.engine.spi.SessionFactoryImplementor ;
import org.hibernate.exception.ConstraintViolationException ;
import org.hibernate.exception.DataException ;
@ -51,6 +55,7 @@ import org.springframework.dao.DuplicateKeyException;
@@ -51,6 +55,7 @@ import org.springframework.dao.DuplicateKeyException;
import org.springframework.dao.IncorrectResultSizeDataAccessException ;
import org.springframework.dao.InvalidDataAccessApiUsageException ;
import org.springframework.dao.InvalidDataAccessResourceUsageException ;
import org.springframework.dao.PessimisticLockingFailureException ;
import org.springframework.jdbc.datasource.DataSourceUtils ;
/ * *
@ -116,7 +121,7 @@ public abstract class SessionFactoryUtils {
@@ -116,7 +121,7 @@ public abstract class SessionFactoryUtils {
/ * *
* Convert the given HibernateException to an appropriate exception
* from the { @code org . springframework . dao } hierarchy .
* @param ex HibernateException that occured
* @param ex HibernateException that occurr ed
* @return the corresponding DataAccessException instance
* @see HibernateExceptionTranslator # convertHibernateAccessException
* @see HibernateTransactionManager # convertHibernateAccessException
@ -129,10 +134,18 @@ public abstract class SessionFactoryUtils {
@@ -129,10 +134,18 @@ public abstract class SessionFactoryUtils {
SQLGrammarException jdbcEx = ( SQLGrammarException ) ex ;
return new InvalidDataAccessResourceUsageException ( ex . getMessage ( ) + "; SQL [" + jdbcEx . getSQL ( ) + "]" , ex ) ;
}
if ( ex instanceof QueryTimeoutException ) {
QueryTimeoutException jdbcEx = ( QueryTimeoutException ) ex ;
return new org . springframework . dao . QueryTimeoutException ( ex . getMessage ( ) + "; SQL [" + jdbcEx . getSQL ( ) + "]" , ex ) ;
}
if ( ex instanceof LockAcquisitionException ) {
LockAcquisitionException jdbcEx = ( LockAcquisitionException ) ex ;
return new CannotAcquireLockException ( ex . getMessage ( ) + "; SQL [" + jdbcEx . getSQL ( ) + "]" , ex ) ;
}
if ( ex instanceof PessimisticLockException ) {
PessimisticLockException jdbcEx = ( PessimisticLockException ) ex ;
return new PessimisticLockingFailureException ( ex . getMessage ( ) + "; SQL [" + jdbcEx . getSQL ( ) + "]" , ex ) ;
}
if ( ex instanceof ConstraintViolationException ) {
ConstraintViolationException jdbcEx = ( ConstraintViolationException ) ex ;
return new DataIntegrityViolationException ( ex . getMessage ( ) + "; SQL [" + jdbcEx . getSQL ( ) +
@ -180,6 +193,15 @@ public abstract class SessionFactoryUtils {
@@ -180,6 +193,15 @@ public abstract class SessionFactoryUtils {
if ( ex instanceof StaleStateException ) {
return new HibernateOptimisticLockingFailureException ( ( StaleStateException ) ex ) ;
}
if ( ex instanceof OptimisticEntityLockException ) {
return new HibernateOptimisticLockingFailureException ( ( OptimisticEntityLockException ) ex ) ;
}
if ( ex instanceof PessimisticEntityLockException ) {
if ( ex . getCause ( ) instanceof LockAcquisitionException ) {
return new CannotAcquireLockException ( ex . getMessage ( ) , ex . getCause ( ) ) ;
}
return new PessimisticLockingFailureException ( ex . getMessage ( ) , ex ) ;
}
// fallback
return new HibernateSystemException ( ex ) ;