Skip to content

Commit e0f1978

Browse files
authored
Merge pull request #1575 from shootercheng/master
Include statement ID in the error message when a referenced result map is missing
2 parents f23f45f + 321e566 commit e0f1978

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ private List<ResultMap> getStatementResultMaps(
337337
try {
338338
resultMaps.add(configuration.getResultMap(resultMapName.trim()));
339339
} catch (IllegalArgumentException e) {
340-
throw new IncompleteElementException("Could not find result map " + resultMapName, e);
340+
throw new IncompleteElementException("Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'", e);
341341
}
342342
}
343343
} else if (resultType != null) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright 2009-2018 the original author or authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
18+
-->
19+
<!DOCTYPE mapper
20+
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
21+
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
22+
<mapper namespace="org.mybatis.spring.ErrorProblemMapper">
23+
24+
<select id="findProblemResultMapTest" resultMap="java.lang.String">
25+
SELECT *
26+
FROM table_test WHERE id = #{id}
27+
</select>
28+
</mapper>

src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,21 @@ void shouldFailedLoadXMLMapperFile() throws Exception {
191191
// builder2.parse();
192192
// }
193193

194+
@Test
195+
public void erorrResultMapLocation() throws Exception {
196+
Configuration configuration = new Configuration();
197+
String resource = "org/apache/ibatis/builder/ProblemResultMapper.xml";
198+
try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
199+
XMLMapperBuilder builder = new XMLMapperBuilder(inputStream, configuration, resource, configuration.getSqlFragments());
200+
builder.parse();
201+
String resultMapName = "java.lang.String";
202+
// namespace + "." + id
203+
String statementId = "org.mybatis.spring.ErrorProblemMapper" + "." + "findProblemResultMapTest";
204+
// same as MapperBuilderAssistant.getStatementResultMaps Exception message
205+
String message = "Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'";
206+
IncompleteElementException exception = Assertions.assertThrows(IncompleteElementException.class,
207+
()-> configuration.getMappedStatement("findProblemTypeTest"));
208+
assertThat(exception.getMessage()).isEqualTo(message);
209+
}
210+
}
194211
}

0 commit comments

Comments
 (0)