iBatis for Java [READ ONLY]
  1. iBatis for Java [READ ONLY]
  2. IBATIS-684

resultMap result column to property mapping in a collection is ignored if a query column matches a bean property

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0 Beta 5
    • Fix Version/s: 3.0 Beta 6
    • Component/s: Core
    • Labels:
      None

      Description

      A bean property was being populated by matching a column from the query instead of a <result> mapping from a <collection> element.
      I would expect the explicit mapping to override the property based bean population from column names but of course this might be an RTFM kind of a bug.

      A non working example bellow. The <result property="name" column="category_name"/> mapping is being ignored in favor of the column name matching the property name in the bean.

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE mapper
      PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
      "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
      <mapper namespace="Channel">

      <resultMap id="channelResult" type="Channel">
      <id property="id" column="channel_id"/>
      <collection property="interestCodes" ofType="InterestCode">
      <id property="id" column="interestcodeid"/>
      <result property="code" column="interestcode"/>
      <result property="codeType" column="InterestCodeTypeId"/>
      <result property="codeType" column="InterestCodeTypeId"/>
      <result property="description" column="description"/>
      </collection>
      <collection property="category" column="categoryId" ofType="Category">
      <id property="id" column="categoryId"/>
      <result property="name" column="category_name"/>
      <result property="left" column="lft"/>
      <result property="right" column="rgt"/>
      </collection>
      </resultMap>

      <select id="selectChannel" parameterType="long" resultMap="channelResult">
      SELECT c.id channel_id, c.name, c.alias, c.type_id typeId, c.default_channel defaultChannel,
      c.commerce_id commerceId, c.subscriber_type subscriberType, c.subscriber_commerce_id subscriberCommerceId,
      c.notes, c.version, ic.interestcodeid, ic.interestcodetypeid, ic.interestcode, ic.description, cat.id categoryId, cat.name category_name, cat.lft, cat.rgt
      FROM CHANNELS_NR c
      LEFT OUTER JOIN SIMPLE_CHANNEL_DEFINITIONS scd ON (c.id = scd.channel_id)
      LEFT OUTER JOIN INTEREST_CODES ic ON (scd.definition = ic.InterestCode)
      LEFT OUTER JOIN CHANNEL_CATEGORY_NR cc ON (c.id = cc.channel_id)
      LEFT OUTER JOIN CATEGORY_NR cat ON (cc.category_id = cat.id)
      WHERE c.id = #

      {id}
      </select>
      </mapper>

      I resolved this by aliasing c.name channel_name and adding <result property="name" column="channel_name"/> in the <resultMap>

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE mapper
      PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
      "http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
      <mapper namespace="Channel">

      <resultMap id="channelResult" type="Channel">
      <id property="id" column="channel_id"/>
      <result property="name" column="channel_name"/>
      <collection property="interestCodes" ofType="InterestCode">
      <id property="id" column="interestcodeid"/>
      <result property="code" column="interestcode"/>
      <result property="codeType" column="InterestCodeTypeId"/>
      <result property="codeType" column="InterestCodeTypeId"/>
      <result property="description" column="description"/>
      </collection>
      <collection property="category" column="categoryId" ofType="Category">
      <id property="id" column="categoryId"/>
      <result property="name" column="category_name"/>
      <result property="left" column="lft"/>
      <result property="right" column="rgt"/>
      </collection>
      </resultMap>

      <select id="selectChannel" parameterType="long" resultMap="channelResult">
      SELECT c.id channel_id, c.name channel_name, c.alias, c.type_id typeId, c.default_channel defaultChannel,
      c.commerce_id commerceId, c.subscriber_type subscriberType, c.subscriber_commerce_id subscriberCommerceId,
      c.notes, c.version, ic.interestcodeid, ic.interestcodetypeid, ic.interestcode, ic.description, cat.id categoryId, cat.name category_name, cat.lft, cat.rgt
      FROM CHANNELS_NR c
      LEFT OUTER JOIN SIMPLE_CHANNEL_DEFINITIONS scd ON (c.id = scd.channel_id)
      LEFT OUTER JOIN INTEREST_CODES ic ON (scd.definition = ic.InterestCode)
      LEFT OUTER JOIN CHANNEL_CATEGORY_NR cc ON (c.id = cc.channel_id)
      LEFT OUTER JOIN CATEGORY_NR cat ON (cc.category_id = cat.id)
      WHERE c.id = #{id}

      </select>
      </mapper>

        Activity

        Eli Kizhnerman created issue -
        Clinton Begin made changes -
        Field Original Value New Value
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Clinton Begin [ cbegin ]
        Fix Version/s 3.0 Beta 6 [ 12314344 ]

          People

          • Assignee:
            Clinton Begin
            Reporter:
            Eli Kizhnerman
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development