Skip to content

Commit fc73779

Browse files
杜龙harawata
杜龙
authored andcommitted
avoid unexpected automapping when a explicit mapped proerty has the same name as another column
1 parent 3c91ef3 commit fc73779

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ private List<UnMappedColumnAutoMapping> createAutomaticMappings(ResultSetWrapper
477477
}
478478
}
479479
final String property = metaObject.findProperty(propertyName, configuration.isMapUnderscoreToCamelCase());
480-
if (property != null && metaObject.hasSetter(property)) {
480+
if (property != null && metaObject.hasSetter(property) && !resultMap.getMappedProperties().contains(property)) {
481481
final Class<?> propertyType = metaObject.getSetterType(property);
482482
if (typeHandlerRegistry.hasTypeHandler(propertyType, rsw.getJdbcType(columnName))) {
483483
final TypeHandler<?> typeHandler = rsw.getTypeHandler(propertyType, columnName);

src/main/java/org/apache/ibatis/mapping/ResultMap.java

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ResultMap {
3535
private List<ResultMapping> constructorResultMappings;
3636
private List<ResultMapping> propertyResultMappings;
3737
private Set<String> mappedColumns;
38+
private Set<String> mappedProperties;
3839
private Discriminator discriminator;
3940
private boolean hasNestedResultMaps;
4041
private boolean hasNestedQueries;
@@ -71,6 +72,7 @@ public ResultMap build() {
7172
throw new IllegalArgumentException("ResultMaps must have an id");
7273
}
7374
resultMap.mappedColumns = new HashSet<String>();
75+
resultMap.mappedProperties = new HashSet<String>();
7476
resultMap.idResultMappings = new ArrayList<ResultMapping>();
7577
resultMap.constructorResultMappings = new ArrayList<ResultMapping>();
7678
resultMap.propertyResultMappings = new ArrayList<ResultMapping>();
@@ -88,6 +90,10 @@ public ResultMap build() {
8890
}
8991
}
9092
}
93+
final String property = resultMapping.getProperty();
94+
if(property != null) {
95+
resultMap.mappedProperties.add(property);
96+
}
9197
if (resultMapping.getFlags().contains(ResultFlag.CONSTRUCTOR)) {
9298
resultMap.constructorResultMappings.add(resultMapping);
9399
} else {
@@ -146,6 +152,10 @@ public Set<String> getMappedColumns() {
146152
return mappedColumns;
147153
}
148154

155+
public Set<String> getMappedProperties() {
156+
return mappedProperties;
157+
}
158+
149159
public Discriminator getDiscriminator() {
150160
return discriminator;
151161
}

0 commit comments

Comments
 (0)