I have a class with recursive relation like below.
Class A{
String id;
String op;
String val;
List<A> aList;
}
I am using MySQL MyBatis to generate a query like below.
<sql id="testRecursion">
<foreach collection="A.aList" item="aList" open="(" separator=" UNION " close=")">
<if test="aList.op == null">
(
SELECT sum(val) as val FROM
FROM test_data
WHERE id = #{aList.id}
)
</if>
<if test="aList.op== 'AND'">
SELECT max(val) as val FROM
<include refid="testRecursion"/>
</if>
<if test="aList.op== 'OR'">
SELECT min(val) as val FROM
<include refid="testRecursion"/>
</if>
</foreach>
</sql>
It is giving below error with stack overflow exception like this while on the compilation.
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.applyIncludes(XMLIncludeTransformer.java:74) ~[mybatis-3.4.5.jar:3.4.5]
at org.apache.ibatis.builder.xml.XMLIncludeTransformer.applyIncludes(XMLIncludeTransformer.java:62) ~[mybatis-3.4.5.jar:3.4.5]
Can someone please help me out here, how to implement recursion in mybatis.