|
9 | 9 | import static org.apache.ibatis.mapping.SqlCommandType.UPDATE;
|
10 | 10 |
|
11 | 11 | import java.util.ArrayList;
|
| 12 | +import java.util.Collections; |
12 | 13 | import java.util.HashMap;
|
13 | 14 | import java.util.HashSet;
|
14 | 15 | import java.util.List;
|
|
42 | 43 | import org.apache.ibatis.executor.keygen.NoKeyGenerator;
|
43 | 44 | import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
|
44 | 45 | import org.apache.ibatis.mapping.MappedStatement;
|
| 46 | +import org.apache.ibatis.mapping.ResultFlag; |
45 | 47 | import org.apache.ibatis.mapping.ResultMapping;
|
46 | 48 | import org.apache.ibatis.session.Configuration;
|
47 | 49 |
|
@@ -84,32 +86,32 @@ private void addResultMap() {
|
84 | 86 |
|
85 | 87 | if (p.isAnnotationPresent(EmbeddedId.class) || p.isEmbeddable()) {
|
86 | 88 |
|
87 |
| - List<ResultMapping> nestedResultMappings = new ArrayList<>(); |
88 |
| - |
89 | 89 | ((MybatisPersistentEntityImpl) entity)
|
90 | 90 | .getRequiredPersistentEntity(p.getActualType()).doWithProperties(
|
91 | 91 | (PropertyHandler<MybatisPersistentProperty>) ep -> {
|
92 |
| - // build mybatis result map association |
93 |
| - nestedResultMappings.add(assistant.buildResultMapping( |
94 |
| - ep.getType(), ep.getName(), |
95 |
| - ep.getColumnName(), ep.getType(), |
96 |
| - ep.getJdbcType(), null, null, null, null, |
97 |
| - ep.getSpecifiedTypeHandler(), null)); |
| 92 | + |
| 93 | + resultMappings.add( |
| 94 | + assistant.buildResultMapping(ep.getType(), |
| 95 | + String.format("%s.%s", p.getName(), |
| 96 | + ep.getName()), |
| 97 | + ep.getColumnName(), ep.getType(), |
| 98 | + ep.getJdbcType(), null, null, null, |
| 99 | + null, ep.getSpecifiedTypeHandler(), |
| 100 | + p.isIdProperty() |
| 101 | + ? Collections.singletonList( |
| 102 | + ResultFlag.ID) |
| 103 | + : null)); |
98 | 104 |
|
99 | 105 | });
|
100 |
| - addResultMap(RESULT_MAP + "_" + p.getName(), p.getActualType(), |
101 |
| - nestedResultMappings); |
102 |
| - resultMappings.add(assistant.buildResultMapping(p.getType(), p.getName(), |
103 |
| - p.getColumnName(), p.getType(), p.getJdbcType(), null, |
104 |
| - RESULT_MAP + "_" + p.getName(), null, null, |
105 |
| - p.getSpecifiedTypeHandler(), null)); |
106 |
| - } |
107 |
| - else { |
108 |
| - resultMappings.add(assistant.buildResultMapping(p.getType(), p.getName(), |
109 |
| - p.getColumnName(), p.getType(), p.getJdbcType(), null, null, null, |
110 |
| - null, p.getSpecifiedTypeHandler(), null)); |
| 106 | + |
| 107 | + return; |
111 | 108 | }
|
112 | 109 |
|
| 110 | + resultMappings.add(assistant.buildResultMapping(p.getType(), p.getName(), |
| 111 | + p.getColumnName(), p.getType(), p.getJdbcType(), null, null, null, |
| 112 | + null, p.getSpecifiedTypeHandler(), |
| 113 | + p.isIdProperty() ? Collections.singletonList(ResultFlag.ID) : null)); |
| 114 | + |
113 | 115 | });
|
114 | 116 |
|
115 | 117 | addResultMap(RESULT_MAP, entity.getType(), resultMappings);
|
|
0 commit comments