Skip to content

Commit 2a0714b

Browse files
committed
converted EmptyResultDataAccessException preserves JPA NoResultException as root cause (SPR-9041)
1 parent efd2783 commit 2a0714b

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -306,7 +306,7 @@ public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeExc
306306
return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
307307
}
308308
if (ex instanceof NoResultException) {
309-
return new EmptyResultDataAccessException(ex.getMessage(), 1);
309+
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
310310
}
311311
if (ex instanceof NonUniqueResultException) {
312312
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,4 +43,14 @@ public EmptyResultDataAccessException(String msg, int expectedSize) {
4343
super(msg, expectedSize, 0);
4444
}
4545

46+
/**
47+
* Constructor for EmptyResultDataAccessException.
48+
* @param msg the detail message
49+
* @param expectedSize the expected result size
50+
* @param ex the wrapped exception
51+
*/
52+
public EmptyResultDataAccessException(String msg, int expectedSize, Throwable ex) {
53+
super(msg, expectedSize, 0, ex);
54+
}
55+
4656
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2006 the original author or authors.
2+
* Copyright 2002-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -68,8 +68,8 @@ public IncorrectResultSizeDataAccessException(String msg, int expectedSize) {
6868
/**
6969
* Constructor for IncorrectResultSizeDataAccessException.
7070
* @param msg the detail message
71-
* @param ex the wrapped exception
7271
* @param expectedSize the expected result size
72+
* @param ex the wrapped exception
7373
*/
7474
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, Throwable ex) {
7575
super(msg, ex);
@@ -89,19 +89,32 @@ public IncorrectResultSizeDataAccessException(String msg, int expectedSize, int
8989
this.actualSize = actualSize;
9090
}
9191

92+
/**
93+
* Constructor for IncorrectResultSizeDataAccessException.
94+
* @param msg the detail message
95+
* @param expectedSize the expected result size
96+
* @param actualSize the actual result size (or -1 if unknown)
97+
* @param ex the wrapped exception
98+
*/
99+
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, int actualSize, Throwable ex) {
100+
super(msg, ex);
101+
this.expectedSize = expectedSize;
102+
this.actualSize = actualSize;
103+
}
104+
92105

93106
/**
94107
* Return the expected result size.
95108
*/
96109
public int getExpectedSize() {
97-
return expectedSize;
110+
return this.expectedSize;
98111
}
99112

100113
/**
101114
* Return the actual result size (or -1 if unknown).
102115
*/
103116
public int getActualSize() {
104-
return actualSize;
117+
return this.actualSize;
105118
}
106119

107120
}

0 commit comments

Comments
 (0)