Browse Source

Properly return SQLExceptionTranslator-provided exception

Closes gh-31409
pull/31598/head
Juergen Hoeller 1 year ago
parent
commit
704650de6d
  1. 4
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java
  2. 2
      spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java
  3. 6
      spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java

4
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 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.
@ -96,7 +96,7 @@ public class HibernateExceptionTranslator implements PersistenceExceptionTransla @@ -96,7 +96,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);

2
spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateTransactionManager.java

@ -777,8 +777,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana @@ -777,8 +777,6 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
/**
* Convert the given HibernateException to an appropriate exception
* from the {@code org.springframework.dao} hierarchy.
* <p>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

6
spring-orm/src/main/java/org/springframework/orm/jpa/vendor/HibernateJpaDialect.java vendored

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@ -124,8 +124,8 @@ public class HibernateJpaDialect extends DefaultJpaDialect { @@ -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;
@ -247,7 +247,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { @@ -247,7 +247,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;
}
}

Loading…
Cancel
Save