38
38
import org .springframework .dao .InvalidDataAccessApiUsageException ;
39
39
import org .springframework .jdbc .support .JdbcUtils ;
40
40
import org .springframework .util .Assert ;
41
+ import org .springframework .util .ClassUtils ;
41
42
import org .springframework .util .StringUtils ;
42
43
43
44
/**
@@ -257,22 +258,27 @@ public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
257
258
258
259
for (int index = 1 ; index <= columnCount ; index ++) {
259
260
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 );
261
263
if (pd != null ) {
262
264
try {
263
265
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 ()) + "]" );
267
269
}
268
270
try {
269
271
bw .setPropertyValue (pd .getName (), value );
270
272
}
271
273
catch (TypeMismatchException ex ) {
272
274
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
+ }
276
282
}
277
283
else {
278
284
throw ex ;
@@ -284,14 +290,21 @@ public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
284
290
}
285
291
catch (NotWritablePropertyException ex ) {
286
292
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 + "'" );
288
300
}
289
301
}
290
302
}
291
303
292
304
if (populatedProperties != null && !populatedProperties .equals (this .mappedProperties )) {
293
305
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 );
295
308
}
296
309
297
310
return mappedObject ;
0 commit comments