MyBatis的不从查询返回的所有结果 [英] MyBatis doesn't return all the results from the query

查看:879
本文介绍了MyBatis的不从查询返回的所有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回17条记录的查询。当我使用的MyBatis与具有&LT地图;联想> 返回6条。的请注意,这不符合我的其他地图发生了,我有很多其他的地图,协会各项工作的罚款。

I have a query that returns 17 records. When I use MyBatis with a map that has an <association> it returns 6 records. Note that this doesn't happen with my other maps, I have many other maps with associations that all work fine.

查询:

    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

图:

<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>

&LT;联想&GT; typeCountMap 指的是地图 MYMAP

这将返回6条记录每一次。从拼抢记录仪的实际运行查询并运行它手动返回17条记录。

This returns 6 records every time. Grabbing the actual query run from the logger and running it manually returns 17 records.

有两件事情我可以做的就是MyBatis的返回所有17条记录

1

如果我删除 lc.count为count_nm 从我的查询我得到的所有17条记录返回(只是没有与之关联的值)

If I remove the lc.count as count_nm from my query I get all 17 records returned (just with no values associated with them)

    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 this in case it would help you figure out what I'm doing wrong.

2

如果我与其他地图的一切的内容替换协会评为预期工作。

If I replace the association with the contents of the other map everything works 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>

这显然是什么,如果我没有找到另一种解决办法我会做,因为这样做的工作。这纯粹是不错的使用&LT;结社方式&gt; 就像我在其他地图

This obviously is what I'll do if I don't find another solution, since this does work. It would just be nice to use the <association> like I have in other maps.

我要指出,我使用的MyBatis 3.1.1

I should note that I am using MyBatis 3.1.1

推荐答案

我不知道这是一个问题,但它的一些尝试。我有,因为我没有足够的代表处发表评论在这里发表。

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.

尝试添加一列属性的关联和标记在第二张图中的ID列:

Try adding a column attribute to your association and marking the ID column in the 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>

这篇关于MyBatis的不从查询返回的所有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆