Skip to content

Commit b5cf787

Browse files
committed
Corrected inconsistency between autoMapping=true and false when callSetterOnNull is true. Related to #307 and #62 .
1 parent 5917285 commit b5cf787

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ private boolean applyPropertyMappings(ResultSetWrapper rsw, ResultMap resultMap,
435435
foundValues = true;
436436
metaObject.setValue(property, value);
437437
} else if (configuration.isCallSettersOnNulls() && !metaObject.getSetterType(property).isPrimitive()) {
438-
// issue #377, call setter on nulls (value is not 'found')
438+
// gcode issue #377, call setter on nulls (value is not 'found')
439439
metaObject.setValue(property, value);
440440
}
441441
}
@@ -504,8 +504,7 @@ private boolean applyAutomaticMappings(ResultSetWrapper rsw, ResultMap resultMap
504504
foundValues = true;
505505
metaObject.setValue(mapping.property, value);
506506
} else if (configuration.isCallSettersOnNulls() && !mapping.primitive) {
507-
// issue #377, call setter on nulls
508-
foundValues = true;
507+
// gcode issue #377, call setter on nulls (value is not 'found')
509508
metaObject.setValue(mapping.property, value);
510509
}
511510
}

src/test/java/org/apache/ibatis/submitted/call_setters_on_nulls/CallSettersOnNullsTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2016 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.
@@ -95,7 +95,10 @@ public void shouldCallNullOnMapForSingleColumn() {
9595
try {
9696
Mapper mapper = sqlSession.getMapper(Mapper.class);
9797
List<Map<String, Object>> oneColumns = mapper.getNameOnly();
98-
Assert.assertNotNull(oneColumns.get(1));
98+
// When callSetterOnNull is true, setters are called with null values
99+
// but if all the values for an object are null
100+
// the object itself should be null (same as default behaviour)
101+
Assert.assertNull(oneColumns.get(1));
99102
} finally {
100103
sqlSession.close();
101104
}

0 commit comments

Comments
 (0)