Skip to content

Commit

Permalink
converted EmptyResultDataAccessException preserves JPA NoResultExcept…
Browse files Browse the repository at this point in the history
…ion as root cause (SPR-9041)
  • Loading branch information
jhoeller committed Feb 8, 2012
1 parent efd2783 commit 2a0714b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
Expand Down Expand Up @@ -306,7 +306,7 @@ public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeExc
return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
}
if (ex instanceof NoResultException) {
return new EmptyResultDataAccessException(ex.getMessage(), 1);
return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
}
if (ex instanceof NonUniqueResultException) {
return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2012 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.
Expand Down Expand Up @@ -43,4 +43,14 @@ public EmptyResultDataAccessException(String msg, int expectedSize) {
super(msg, expectedSize, 0);
}

/**
* Constructor for EmptyResultDataAccessException.
* @param msg the detail message
* @param expectedSize the expected result size
* @param ex the wrapped exception
*/
public EmptyResultDataAccessException(String msg, int expectedSize, Throwable ex) {
super(msg, expectedSize, 0, ex);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2012 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.
Expand Down Expand Up @@ -68,8 +68,8 @@ public IncorrectResultSizeDataAccessException(String msg, int expectedSize) {
/**
* Constructor for IncorrectResultSizeDataAccessException.
* @param msg the detail message
* @param ex the wrapped exception
* @param expectedSize the expected result size
* @param ex the wrapped exception
*/
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, Throwable ex) {
super(msg, ex);
Expand All @@ -89,19 +89,32 @@ public IncorrectResultSizeDataAccessException(String msg, int expectedSize, int
this.actualSize = actualSize;
}

/**
* Constructor for IncorrectResultSizeDataAccessException.
* @param msg the detail message
* @param expectedSize the expected result size
* @param actualSize the actual result size (or -1 if unknown)
* @param ex the wrapped exception
*/
public IncorrectResultSizeDataAccessException(String msg, int expectedSize, int actualSize, Throwable ex) {
super(msg, ex);
this.expectedSize = expectedSize;
this.actualSize = actualSize;
}


/**
* Return the expected result size.
*/
public int getExpectedSize() {
return expectedSize;
return this.expectedSize;
}

/**
* Return the actual result size (or -1 if unknown).
*/
public int getActualSize() {
return actualSize;
return this.actualSize;
}

}

0 comments on commit 2a0714b

Please sign in to comment.