diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOptimisticLockingFailureException.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOptimisticLockingFailureException.java index 96d7b3e155..43c73be221 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOptimisticLockingFailureException.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/HibernateOptimisticLockingFailureException.java @@ -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. @@ -16,6 +16,7 @@ package org.springframework.orm.hibernate3; +import org.hibernate.OptimisticLockException; import org.hibernate.StaleObjectStateException; import org.hibernate.StaleStateException; @@ -23,7 +24,8 @@ import org.springframework.orm.ObjectOptimisticLockingFailureException; /** * Hibernate-specific subclass of ObjectOptimisticLockingFailureException. - * Converts Hibernate's StaleObjectStateException and StaleStateException. + * Converts Hibernate's StaleObjectStateException, StaleStateException + * and OptimisticLockException. * * @author Juergen Hoeller * @since 1.2 @@ -40,4 +42,8 @@ public class HibernateOptimisticLockingFailureException extends ObjectOptimistic super(ex.getMessage(), ex); } + public HibernateOptimisticLockingFailureException(OptimisticLockException ex) { + super(ex.getMessage(), ex); + } + } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java b/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java index a6e13b673d..d1ae6a3b86 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java @@ -35,10 +35,13 @@ import org.hibernate.JDBCException; import org.hibernate.NonUniqueObjectException; import org.hibernate.NonUniqueResultException; import org.hibernate.ObjectDeletedException; +import org.hibernate.OptimisticLockException; import org.hibernate.PersistentObjectException; +import org.hibernate.PessimisticLockException; import org.hibernate.PropertyValueException; import org.hibernate.Query; import org.hibernate.QueryException; +import org.hibernate.QueryTimeoutException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.StaleObjectStateException; @@ -63,6 +66,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; import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator; import org.springframework.jdbc.support.SQLExceptionTranslator; @@ -87,6 +91,8 @@ import org.springframework.util.Assert; * and {@link HibernateTransactionManager}. Can also be used directly in * application code. * + *
Requires Hibernate 3.6 or later, as of Spring 4.0. + * * @author Juergen Hoeller * @since 1.2 * @see #getSession @@ -634,10 +640,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() + @@ -685,6 +699,9 @@ public abstract class SessionFactoryUtils { if (ex instanceof StaleStateException) { return new HibernateOptimisticLockingFailureException((StaleStateException) ex); } + if (ex instanceof OptimisticLockException) { + return new HibernateOptimisticLockingFailureException((OptimisticLockException) ex); + } // fallback return new HibernateSystemException(ex);