Problem
I have a query that returns 17 records. When I use MyBatis with a map with <association> , it returns 6 records. Please note that this does not happen with my other cards, I have many other cards with associations that work fine.
Query:
with leave_counts as ( select leave_type_id, count(llm.leave_id) as count from lw_leave_master llm group by leave_type_id ) select llt.leave_type_id, llt.leave_type_abbr_tx, llt.leave_type_desc_tx, lc.count as count_nm from lw_leave_type llt join leave_counts lc on lc.leave_type_id=llt.leave_type_id order by llt.leave_type_abbr_tx
Map
<resultMap id="typeCountMap" type="mypackage.myclass"> <result property="count" column="count_nm"/> <association property="type" resultMap="package.myMap"/> </resultMap> <resultMap id="myMap" type="mypackage.myclass2"> <result property="id" column="leave_type_id"/> <result property="abbr" column="leave_type_abbr_tx"/> <result property="description" column="leave_type_desc_tx"/> </resultMap>
<association> in typeCountMap refers to the myMap map.
This returns 6 records each time. Capturing the actual start of the request from the registrar and manually starting it returns 17 records.
Solutions?
I can do two things so that MyBatis can return all 17 records
# 1
If I remove lc.count as count_nm from my query, I will get all 17 records (only without associated values)
with leave_counts as ( select leave_type_id, count(llm.leave_id) as count from lw_leave_master llm group by leave_type_id ) select llt.leave_type_id, llt.leave_type_abbr_tx, llt.leave_type_desc_tx from lw_leave_type llt join leave_counts lc on lc.leave_type_id=llt.leave_type_id order by llt.leave_type_abbr_tx
This is obviously not a good solution, but I wanted to include it if it helps you understand what I'm doing wrong.
# 2
If I replace the link with the contents of another card, everything will work as expected.
<resultMap id="typeCountMap" type="mypackage.myclass1"> <result property="count" column="count_nm"/> <result property="type.id" column="leave_type_id"/> <result property="type.abbr" column="leave_type_abbr_tx"/> <result property="type.description" column="leave_type_desc_tx"/> </resultMap>
This is obviously what I will do if I cannot find another solution, as it works. It would be nice to use <association> , as on other maps.
I should note that I am using MyBatis 3.1.1