Skip to content

Commit 66a96f5

Browse files
committed
A test case that shows how namespace is resolved in a nested include
Several users reported this behavior as a bug, but it is by design. #2590 #3246 #3306
1 parent 4a6c025 commit 66a96f5

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

src/test/java/org/apache/ibatis/submitted/includes/IncludeTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 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.
@@ -57,4 +57,10 @@ void testParametrizedIncludes() {
5757
}
5858
}
5959

60+
@Test
61+
void shouldNamespaceBeResolvedAfterIncluded() {
62+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
63+
Assertions.assertNotNull(sqlSession.selectList("org.apache.ibatis.submitted.includes.mapper.selectIds"));
64+
}
65+
}
6066
}

src/test/resources/org/apache/ibatis/submitted/includes/Fragments.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2023 the original author or authors.
4+
Copyright 2009-2024 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -30,4 +30,8 @@
3030
<sql id="values">
3131
VALUES (1);
3232
</sql>
33+
<sql id="selectId">
34+
select id from
35+
<include refid="tableName" />
36+
</sql>
3337
</mapper>

src/test/resources/org/apache/ibatis/submitted/includes/Mapper.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2022 the original author or authors.
4+
Copyright 2009-2024 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -24,6 +24,9 @@
2424
<sql id="sometable">
2525
${prefix}Table
2626
</sql>
27+
<sql id="tableName">
28+
SomeTable
29+
</sql>
2730

2831
<sql id="someinclude">
2932
<include refid="${include_target}"/>
@@ -54,4 +57,8 @@
5457
Field3 = #{field3,jdbcType=VARCHAR},
5558
where field1 = #{field1,jdbcType=INTEGER}
5659
</update>
60+
61+
<select id="selectIds" resultType="int">
62+
<include refid="org.apache.ibatis.submitted.includes.fragments.selectId"/>
63+
</select>
5764
</mapper>

0 commit comments

Comments
 (0)