Skip to content

Commit 3becd0a

Browse files
committed
fixes #1590 Ensure composite to be empty when unnecessary column is specified
Although more active solution (e.g. output a warning) might be better, there could be a use case that I am not aware of.
1 parent a094323 commit 3becd0a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/main/java/org/apache/ibatis/builder/MapperBuilderAssistant.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.apache.ibatis.builder;
1717

1818
import java.util.ArrayList;
19+
import java.util.Collections;
1920
import java.util.HashMap;
2021
import java.util.HashSet;
2122
import java.util.List;
@@ -369,7 +370,12 @@ public ResultMapping buildResultMapping(
369370
boolean lazy) {
370371
Class<?> javaTypeClass = resolveResultJavaType(resultType, property, javaType);
371372
TypeHandler<?> typeHandlerInstance = resolveTypeHandler(javaTypeClass, typeHandler);
372-
List<ResultMapping> composites = parseCompositeColumnName(column);
373+
List<ResultMapping> composites;
374+
if ((nestedSelect == null || nestedSelect.isEmpty()) && (foreignColumn == null || foreignColumn.isEmpty())) {
375+
composites = Collections.emptyList();
376+
} else {
377+
composites = parseCompositeColumnName(column);
378+
}
373379
return new ResultMapping.Builder(configuration, property, column, javaTypeClass)
374380
.jdbcType(jdbcType)
375381
.nestedQueryId(applyCurrentNamespace(nestedSelect, true))

src/test/java/org/apache/ibatis/submitted/associationtest/Mapper.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
<id column="carid" property="id"/>
2727
<result column="cartype" property="type"/>
2828
<association property="engine" resultMap="engineResult"/>
29-
<association property="brakes" resultMap="brakesResult"/>
29+
<!-- the bogus 'column' below is to assert gh-1590 -->
30+
<association property="brakes" resultMap="brakesResult" column="{carid=carid}" />
3031
</resultMap>
3132
<resultMap type="org.apache.ibatis.submitted.associationtest.Engine" id="engineResult">
3233
<result column="enginetype" property="type"/>

0 commit comments

Comments
 (0)