Skip to content Skip to sidebar Skip to footer

Mybatis Doesn't Return All The Results From The Query

The Problem I have a query that returns 17 records. When I use MyBatis with a map that has an it returns 6 records. Note that this doesn't happen with my other

Solution 1:

I recently ran into this same problem. I believe the issue was related to my main resultMap with the association in it not having an id column while my association's resultMap did have an id column. My results were getting grouped by the associations id column.

To correct the issue I selected the row number in my query and added an id to my main resultMap pointing to the row number column.

Solution 2:

If you're using 3.1.1 you can define just <id column="leave_type_id" /> without property attribute If you're not using 3.1.1 you can add <result property="abbr" column="leave_type_id" /> on top of the list to include field into cache key calculation for association, later re-definition will assign correct value

Solution 3:

I don't know if this is the problem, but it's something to try. I have to post here because I don't have enough rep to leave a comment.

Try adding a column attribute to your association and marking the ID column in the second map:

<resultMapid="typeCountMap"type="mypackage.myclass"><resultproperty="count"column="count_nm"/><associationproperty="type"column="leave_type_id"resultMap="package.myMap"/></resultMap><resultMapid="myMap"type="mypackage.myclass2"><idproperty="id"column="leave_type_id"/><resultproperty="abbr"column="leave_type_abbr_tx"/><resultproperty="description"column="leave_type_desc_tx"/></resultMap>

Solution 4:

You should replace the line <result property="id" column="leave_type_id"/>

with <id property="id" column="leave_type_id"/>.

In mybatis you should not miss to specify the id column it may mess up with your result set.

Post a Comment for "Mybatis Doesn't Return All The Results From The Query"