From 66ce8c9a253727c673f38e65554cefb7eb6a23fc Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 11 Oct 2023 13:13:22 +0200 Subject: [PATCH] Properly return SQLExceptionTranslator-provided exception Closes gh-31409 --- .../orm/hibernate5/HibernateExceptionTranslator.java | 2 +- .../orm/hibernate5/HibernateTransactionManager.java | 2 -- .../springframework/orm/jpa/vendor/HibernateJpaDialect.java | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java index 96c0c26e76..fc247d49f5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java @@ -94,7 +94,7 @@ public class HibernateExceptionTranslator implements PersistenceExceptionTransla DataAccessException dae = this.jdbcExceptionTranslator.translate( "Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException()); if (dae != null) { - throw dae; + return dae; } } return SessionFactoryUtils.convertHibernateAccessException(ex); diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java index e4b7f1c83c..1cc32b0aea 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java @@ -784,8 +784,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana /** * Convert the given HibernateException to an appropriate exception * from the {@code org.springframework.dao} hierarchy. - *

Will automatically apply a specified SQLExceptionTranslator to a - * Hibernate JDBCException, else rely on Hibernate's default translation. * @param ex the HibernateException that occurred * @return a corresponding DataAccessException * @see SessionFactoryUtils#convertHibernateAccessException diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java index ae1f787509..5be0c6c28e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java @@ -124,8 +124,8 @@ public class HibernateJpaDialect extends DefaultJpaDialect { * @since 5.1 * @see java.sql.SQLException * @see org.hibernate.JDBCException + * @see org.springframework.jdbc.support.SQLExceptionSubclassTranslator * @see org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator - * @see org.springframework.jdbc.support.SQLStateSQLExceptionTranslator */ public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTranslator) { this.jdbcExceptionTranslator = jdbcExceptionTranslator; @@ -245,7 +245,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { DataAccessException dae = this.jdbcExceptionTranslator.translate( "Hibernate operation: " + jdbcEx.getMessage(), jdbcEx.getSQL(), jdbcEx.getSQLException()); if (dae != null) { - throw dae; + return dae; } }