sql - MyBatis doesn't return all the results from the query -
the problem
i have query returns 17 records. when use mybatis map has <association>
returns 6 records. note doesn't happen other maps, have many other maps associations work fine.
query:
leave_counts ( select leave_type_id, count(llm.leave_id) count lw_leave_master llm group leave_type_id ) select llt.leave_type_id, llt.leave_type_abbr_tx, llt.leave_type_desc_tx, lc.count count_nm lw_leave_type llt join leave_counts lc on lc.leave_type_id=llt.leave_type_id order 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>
the <association>
in typecountmap
refers map mymap
.
this returns 6 records every time. grabbing actual query run logger , running manually returns 17 records.
solutions?
there 2 things can mybatis return 17 records
#1
if remove lc.count count_nm
query 17 records returned (just no values associated them)
leave_counts ( select leave_type_id, count(llm.leave_id) count lw_leave_master llm group leave_type_id ) select llt.leave_type_id, llt.leave_type_abbr_tx, llt.leave_type_desc_tx lw_leave_type llt join leave_counts lc on lc.leave_type_id=llt.leave_type_id order llt.leave_type_abbr_tx
this not solution, wanted include in case figure out i'm doing wrong.
#2
if replace association contents of other map works 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 i'll if don't find solution, since work. nice use <association>
have in other maps.
i should note using mybatis 3.1.1
i don't know if problem, it's try. have post here because don't have enough rep leave comment.
try adding column attribute association , marking id column in second map:
<resultmap id="typecountmap" type="mypackage.myclass"> <result property="count" column="count_nm"/> <association property="type" column="leave_type_id" resultmap="package.mymap"/> </resultmap> <resultmap id="mymap" type="mypackage.myclass2"> <id property="id" column="leave_type_id"/> <result property="abbr" column="leave_type_abbr_tx"/> <result property="description" column="leave_type_desc_tx"/> </resultmap>