Skip to content

Commit 35e1eca

Browse files
committed
BeanPropertyRowMapper logs in case of no corresponding property as well
Issue: SPR-13323
1 parent 74e6213 commit 35e1eca

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/BeanPropertyRowMapper.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.springframework.dao.InvalidDataAccessApiUsageException;
3939
import org.springframework.jdbc.support.JdbcUtils;
4040
import org.springframework.util.Assert;
41+
import org.springframework.util.ClassUtils;
4142
import org.springframework.util.StringUtils;
4243

4344
/**
@@ -257,22 +258,27 @@ public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
257258

258259
for (int index = 1; index <= columnCount; index++) {
259260
String column = JdbcUtils.lookupColumnName(rsmd, index);
260-
PropertyDescriptor pd = this.mappedFields.get(lowerCaseName(column.replaceAll(" ", "")));
261+
String field = lowerCaseName(column.replaceAll(" ", ""));
262+
PropertyDescriptor pd = this.mappedFields.get(field);
261263
if (pd != null) {
262264
try {
263265
Object value = getColumnValue(rs, index, pd);
264-
if (logger.isDebugEnabled() && rowNumber == 0) {
265-
logger.debug("Mapping column '" + column + "' to property '" +
266-
pd.getName() + "' of type " + pd.getPropertyType());
266+
if (rowNumber == 0 && logger.isDebugEnabled()) {
267+
logger.debug("Mapping column '" + column + "' to property '" + pd.getName() +
268+
"' of type [" + ClassUtils.getQualifiedName(pd.getPropertyType()) + "]");
267269
}
268270
try {
269271
bw.setPropertyValue(pd.getName(), value);
270272
}
271273
catch (TypeMismatchException ex) {
272274
if (value == null && this.primitivesDefaultedForNullValue) {
273-
logger.debug("Intercepted TypeMismatchException for row " + rowNumber + " and column '" +
274-
column + "' with null value when setting property '" + pd.getName() +
275-
"' of type " + pd.getPropertyType() + " on object: " + mappedObject);
275+
if (logger.isDebugEnabled()) {
276+
logger.debug("Intercepted TypeMismatchException for row " + rowNumber +
277+
" and column '" + column + "' with null value when setting property '" +
278+
pd.getName() + "' of type [" +
279+
ClassUtils.getQualifiedName(pd.getPropertyType()) +
280+
"] on object: " + mappedObject, ex);
281+
}
276282
}
277283
else {
278284
throw ex;
@@ -284,14 +290,21 @@ public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
284290
}
285291
catch (NotWritablePropertyException ex) {
286292
throw new DataRetrievalFailureException(
287-
"Unable to map column " + column + " to property " + pd.getName(), ex);
293+
"Unable to map column '" + column + "' to property '" + pd.getName() + "'", ex);
294+
}
295+
}
296+
else {
297+
// No PropertyDescriptor found
298+
if (rowNumber == 0 && logger.isDebugEnabled()) {
299+
logger.debug("No property found for column '" + column + "' mapped to field '" + field + "'");
288300
}
289301
}
290302
}
291303

292304
if (populatedProperties != null && !populatedProperties.equals(this.mappedProperties)) {
293305
throw new InvalidDataAccessApiUsageException("Given ResultSet does not contain all fields " +
294-
"necessary to populate object of class [" + this.mappedClass + "]: " + this.mappedProperties);
306+
"necessary to populate object of class [" + this.mappedClass.getName() + "]: " +
307+
this.mappedProperties);
295308
}
296309

297310
return mappedObject;

0 commit comments

Comments
 (0)