You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Perry Nguyen <pf...@gmail.com> on 2007/11/27 03:09:10 UTC

groupBy with multiple resultMaps in iBATIS 2.3

Hi,

I recently updated to iBATIS 2.3 and it has broken my "complex" object 
maps.  Several searches on the mailing list indicate that this is a 
problem but without a resolution or further research.

My basic problem:  I have an "Image" object, that object has "sizes" and 
"flags" properties, basically 1:M with "sizes" and 1:N with "flags".  In 
2.3, my "flags" relationship ends up being 1:N*M, in 2.1.7 (my last used 
version) it was correctly 1:N.

My current workaround will be to downgrade to iBATIS 2.1.7

A short portion of my mappings follow:

  <resultMap id="imageResult" class="Image" groupBy="id">
    <result property="id" column="IMAGE_ID"/>
    <result property="name" column="IMAGE_NAME"/>
    <result property="description" column="IMAGE_DESCRIPTION"/>
    <result property="owner.id" column="IMAGE_OWNER"/>
    <result property="createTime" column="CREATE_TIME"/>
    <result property="uri" column="IMAGE_URI"/>
    <result property="orderMetric" column="ORDER_METRIC"/>
    <result property="dimensions" resultMap="Images.dimensionsResult"/>
    <result property="album.name" column="ALBUM_NAME"/>
    <result property="album.description" column="ALBUM_DESCRIPTION"/>
    <result property="album.id" column="ALBUM_ID"/>
    <result property="album.uri" column="ALBUM_URI"/>
    <result property="album.owner.id" column="ALBUM_OWNER"/>
    <result property="flags" resultMap="Images.imageFlags"/>
  </resultMap>
  <resultMap id="dimensionsResult" class="Dimension" groupBy="id">
    <result property="id" column="SIZE_ID"/>
    <result property="description" column="SIZE_DESCRIPTION"/>
    <result property="width" column="WIDTH"/>
    <result property="height" column="HEIGHT"/>
  </resultMap>
  <resultMap id="imageFlags" class="Flag" groupBy="value,id">
    <result property="id" column="FLAG_ID"/>
    <result property="value" column="FLAG_VALUE"/>
  </resultMap>
  <select id="getById" resultMap="imageResult">
    SELECT
        i.id as IMAGE_ID,
        i.uri as IMAGE_URI,
        i.owner_id as IMAGE_OWNER,
        album_id,
        i.name as IMAGE_NAME,
        i.order_metric as ORDER_METRIC,
        i.add_date as CREATE_TIME,
        i.description as IMAGE_DESCRIPTION,
        width, height,
        sd.id as SIZE_ID,
        sd.description as SIZE_DESCRIPTION,
        a.id as ALBUM_ID,
        a.name as ALBUM_NAME,
        a.owner_id as ALBUM_OWNER,
        a.description as ALBUM_DESCRIPTION,
        a.uri as ALBUM_URI,
        f.flag as FLAG_ID,
        f.value as FLAG_VALUE
    FROM
        images i left join
        imagesizes s on i.id = s.image_id
        left join imagesizedesc sd on sd.id = s.size_desc_id
        left join image_flags f on i.id = f.id
        join albums a on i.album_id = a.id
    WHERE i.id = #value#
  </sql>

Thanks.