Browse Source

Propagate wrapped exception in SessionFactoryUtils

Improve stack traces in certain Hibernate failure cases by properly
chaining the cause exception.

Issue: SPR-7933

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4146 50f2f4bb-b051-0410-bef5-90022cba6387
pull/1/merge
Chris Beams 15 years ago
parent
commit
48089d0925
  1. 2
      org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java
  2. 2
      org.springframework.orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java
  3. 14
      org.springframework.transaction/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java

2
org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryUtils.java

@ -666,7 +666,7 @@ public abstract class SessionFactoryUtils { @@ -666,7 +666,7 @@ public abstract class SessionFactoryUtils {
return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof StaleObjectStateException) {
return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);

2
org.springframework.orm/src/main/java/org/springframework/orm/jpa/EntityManagerFactoryUtils.java

@ -294,7 +294,7 @@ public abstract class EntityManagerFactoryUtils { @@ -294,7 +294,7 @@ public abstract class EntityManagerFactoryUtils {
return new EmptyResultDataAccessException(ex.getMessage(), 1);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof OptimisticLockException) {
return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);

14
org.springframework.transaction/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java

@ -21,9 +21,11 @@ package org.springframework.dao; @@ -21,9 +21,11 @@ package org.springframework.dao;
* for example when expecting a single row but getting 0 or more than 1 rows.
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 1.0.2
* @see EmptyResultDataAccessException
*/
@SuppressWarnings("serial")
public class IncorrectResultSizeDataAccessException extends DataRetrievalFailureException {
private int expectedSize;
@ -63,6 +65,18 @@ public class IncorrectResultSizeDataAccessException extends DataRetrievalFailure @@ -63,6 +65,18 @@ public class IncorrectResultSizeDataAccessException extends DataRetrievalFailure
this.actualSize = -1;
}
/**
* Constructor for IncorrectResultSizeDataAccessException.
* @param msg the detail message
* @param ex the wrapped exception
* @param expectedSize the expected result size
*/
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, Throwable ex) {
super(msg, ex);
this.expectedSize = expectedSize;
this.actualSize = -1;
}
/**
* Constructor for IncorrectResultSizeDataAccessException.
* @param msg the detail message

Loading…
Cancel
Save