Skip to content

Commit 8d1263c

Browse files
author
mhyeon-lee
committed
Enhance IncorrectResultSizeDataAccessException message details.
1 parent 9634e36 commit 8d1263c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

spring-data-jdbc-plus-sql/src/main/java/com/navercorp/spring/data/jdbc/plus/sql/support/JdbcDaoSupport.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ protected <R> Optional<R> selectOne(String sql, SqlParameterSource params, RowMa
291291
}
292292

293293
if (list.size() > 1) {
294-
throw new IncorrectResultSizeDataAccessException(1, list.size());
294+
String message = new StringBuilder()
295+
.append("Result size must be one or zero for findOne operation. result size: ")
296+
.append(list.size())
297+
.append(", sql: ")
298+
.append(sql)
299+
.append(", params:")
300+
.append(params.toString())
301+
.toString();
302+
throw new IncorrectResultSizeDataAccessException(message, 1, list.size());
295303
}
296304
return Optional.ofNullable(list.get(0));
297305
}

spring-data-jdbc-plus-sql/src/main/java/com/navercorp/spring/data/jdbc/plus/sql/support/JdbcRepositorySupport.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,15 @@ protected <R> Optional<R> findOne(String sql, SqlParameterSource params, RowMapp
383383
}
384384

385385
if (list.size() > 1) {
386-
throw new IncorrectResultSizeDataAccessException(1, list.size());
386+
String message = new StringBuilder()
387+
.append("Result size must be one or zero for findOne operation. result size: ")
388+
.append(list.size())
389+
.append(", sql: ")
390+
.append(sql)
391+
.append(", params:")
392+
.append(params.toString())
393+
.toString();
394+
throw new IncorrectResultSizeDataAccessException(message, 1, list.size());
387395
}
388396
return Optional.ofNullable(this.triggerAfterLoad(list.get(0)));
389397
}

spring-jdbc-plus-support/src/main/java/com/navercorp/spring/jdbc/plus/support/parametersource/CompositeSqlParameterSource.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,11 @@ public Object getValue(String paramName) throws IllegalArgumentException {
7474
throw new IllegalArgumentException(
7575
"Can not find '" + paramName + "' parameter in CompositeSqlParameterSource.");
7676
}
77+
78+
@Override
79+
public String toString() {
80+
return "CompositeSqlParameterSource{" +
81+
"sqlParameterSources=" + sqlParameterSources +
82+
'}';
83+
}
7784
}

0 commit comments

Comments
 (0)