Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-250

CLONE -SELECT statement returns unexpected result when 'groupBy' and 'nullValue' are specified in resultMaps.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.5
    • 2.2.0
    • Core
    • None
    • PowerMac G5 1.8GHz dual, 2.25GB RAM, Mac OS X 10.4.2
      Using SqlMaps from tomcat via spring framework.

    Description

      [Preparation]
      – Database
      CREATE TABLE parent ( parentId, parentName );
      CREATE TABLE child ( childId, parentId, childName, childAge );
      INSERT INTO parent ( parentId, parentName ) VALUES ( 1, 'Mr Parent' );

      – Java classes.
      public class Parent
      {
      private int parentId;
      private String parentName;
      private List childList;
      // accessor methods...
      }

      public class Child
      {
      private int childId;
      private String childName;
      private int childAge;
      // accessor methods...
      }

      --SqlMap.
      <sqlMap namespace="Family">
      <resultMap id="parentResult" class="Parent" groupBy="parentId">
      <result property="parentId" column="parentId"/>
      <result property="parentName" column="parentName"/>
      <result property="childList" resultMap="Family.childResult"/>
      </resultMap>
      <resultMap id="childResult" class="Child">
      <result property="childId" column="childId"/>
      <result property="childName" column="childName"/>
      <result property="childAge" column="childAge" nullValue="0"/>
      </resultMap>
      <select id="getParent" resultMap="parentResult" parameterClass="int">
      SELECT
      parent.parentId, parent.parentName,
      child.childId, child.childName, child.childAge
      FROM parent
      LEFT JOIN child ON parent.parentId = child.parentId
      WHERE
      parent.parentId = #value#
      </select>
      </sqlMap>


      [Test]
      Executing statement "getParent" with parameter '1'.

      [Expected result]
      Query returns 1 'Parent' object and 'childList' property of it is empty (doesn't mean null).

      [Actual result]
      The 'childList' property of the returned 'Parent' contains 1 'Child' object.

      [Additional information]
      If 'nullValue' is not specified in 'childResult', it works as expected.
      But this, of course, causes an error if there is a row in the 'child' table and the 'childAge' column is null.

      Attachments

        1. jira_250.zip
          6 kB
          Sven Boden

        Issue Links

          Activity

            People

              sboden Sven Boden
              ave Iwao AVE!
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: