ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mailjoe <mailjoe2...@yahoo.com>
Subject Duplicates when trying to avoid N+1 selects
Date Fri, 11 Jul 2008 14:02:41 GMT

Hi,

We have a ComplexObject made of one instance of aGroup and one instance of
bGroup.
The aGroup is made of a collection of A instances.
The bGroup is made of a colleciton of B instances.

We have one SQL Map for aGroup, and another one for bGroup.

If aGroup contains m A's and bGroup contains n B's, the query given below
returns m*n items in the aGroup and bGroup properties:

    <resultMap class="ComplexObject" id="result" groupBy="id, aGroupId,
bGroupId">
        <result property="id" column="COMPLEX.OBJECT_ID" />
        <result property="aGroup" column="COMPLEX.A_GROUP_ID"
resultMap="aGroup.result" />
        <result property="bGroup" column="COMPLEX.B_GROUP_ID"
resultMap="bGroup.result" />
    </resultMap>
    
    <select id="getById" resultMap="result">
        SELECT * FROM COMPLEX
        INNER JOIN A_GROUP ON A_GROUP_ID = A_GROUP.ID
        INNER JOIN A ON A.GROUP_ID = A_GROUP_ID
        INNER JOIN B_GROUP ON B_GROUP_ID = B_GROUP.ID
        INNER JOIN B ON B.GROUP_ID = B_GROUP_ID        
        WHERE COMPLEX.ID = #value#
    </select>  

Any idea how to fix this bug?

Thanks!
-- 
View this message in context: http://www.nabble.com/Duplicates-when-trying-to-avoid-N%2B1-selects-tp18404580p18404580.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Mime
View raw message