Skip to content

Commit b0b1116

Browse files
committed
Propagate wrapped exception in SessionFactoryUtils
Improve stack traces in certain Hibernate failure cases by properly chaining the cause exception. Issue: SPR-7933
1 parent 6809b23 commit b0b1116

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ public static DataAccessException convertHibernateAccessException(HibernateExcep
666666
return new HibernateObjectRetrievalFailureException((WrongClassException) ex);
667667
}
668668
if (ex instanceof NonUniqueResultException) {
669-
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
669+
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
670670
}
671671
if (ex instanceof StaleObjectStateException) {
672672
return new HibernateOptimisticLockingFailureException((StaleObjectStateException) ex);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeExc
294294
return new EmptyResultDataAccessException(ex.getMessage(), 1);
295295
}
296296
if (ex instanceof NonUniqueResultException) {
297-
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1);
297+
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
298298
}
299299
if (ex instanceof OptimisticLockException) {
300300
return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
* for example when expecting a single row but getting 0 or more than 1 rows.
2222
*
2323
* @author Juergen Hoeller
24+
* @author Chris Beams
2425
* @since 1.0.2
2526
* @see EmptyResultDataAccessException
2627
*/
28+
@SuppressWarnings("serial")
2729
public class IncorrectResultSizeDataAccessException extends DataRetrievalFailureException {
2830

2931
private int expectedSize;
@@ -63,6 +65,18 @@ public IncorrectResultSizeDataAccessException(String msg, int expectedSize) {
6365
this.actualSize = -1;
6466
}
6567

68+
/**
69+
* Constructor for IncorrectResultSizeDataAccessException.
70+
* @param msg the detail message
71+
* @param ex the wrapped exception
72+
* @param expectedSize the expected result size
73+
*/
74+
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, Throwable ex) {
75+
super(msg, ex);
76+
this.expectedSize = expectedSize;
77+
this.actualSize = -1;
78+
}
79+
6680
/**
6781
* Constructor for IncorrectResultSizeDataAccessException.
6882
* @param msg the detail message

0 commit comments

Comments
 (0)