This is the first time I used Ibatis in a project and I'm stucked on
this error. "Exhausted Resultset".
My problem started when i designed my model class like the following:
class MyObject {
private String id;
private String parentId;
private String rootId;
private MyObject root;
private MyObject parent;
private List<MyObject> children;
--- Getters and Setters Here for all attributes.---
}
Why do you need parentId and rootId? Can't you use root and parent instead?
class MyObject {
private String id;
private MyObject root;
private MyObject parent;
private List<MyObject> children;
}
My SQL Map Looks like this:
<resultMap id="result" class="MyObject">
<result property="id" column="ID" />
<result property="parent" column="ID" select="MyObject.getChildren" />
property="parent"? Is this a typo?
<result property="parent" column="PARENT_ID"
select="MyObject.getMyObjectById" />
<result property="root" column="ROOT_ID"
select="MyObject.getMyObjectById" />
</resultMap>
<select id="getChildren" parameterClass="java.lang.String"
resultMap="result">
SELECT ID, ROOT_ID, PARENT_ID FROM MY_OBJECT WHERE PARENT_ID = #value#
</select>
<select id="getMyObjectById" parameterClass="java.lang.String"
resultMap="result">
SELECT ID, ROOT_ID, PARENT_ID FROM MY_OBJECT WHERE ID = #value#
</select>
==============================================================
In the stacktrace it says
javax.servlet.ServletException: SqlMapClient operation; uncategorized
SQLException for SQL []; SQL state [null]; error code [17011];
.
.
.
java.sql.SQLException: Exhausted Resultset
When I remove this line "<result property="root" column="ROOT_ID"
select="MyObject.getMyObjectById" />" from the resultmap, the code works
fine.
This is already the solution. You must avoid the circular dependencies.
Odd, that your code works without removing
<result property="parent" column="PARENT_ID"
select="MyObject.getMyObjectById" />
I assume, you want to build a tree. After loading the tree you can
iterate recursivly over the child nodes and join them with the root node
and the parent node.