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

Provide a way for not creating items from nested ResultMaps when the items contain only null values

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.2.0
    • 2.3.4
    • Core
    • None

    Description

      Taken the following resultmaps (uneeded parts are left out) for a simple domainmodel where notebook contains 0 or more pages.

      <resultMap class="notebook" groupBy="id" id="notebookResult">
      <result column="NB_ID" jdbcType="VARCHAR" property="id"/>
      <result javaType="java.util.List" property="pages" resultMap="Note.pageResult"/>
      </resultMap>

      <resultMap class="page" groupBy="id" id="pageResult">
      <result column="P_ID" jdbcType="VARCHAR" property="id"/>
      </resultMap>

      and the following select statement:
      <select id="selectNotebook" parameterClass="java.lang.String" resultMap="notebookResult">
      SELECT nb.id as nb_id, p.id as p_id,
      FROM notebook nb LEFT JOIN page p ON nb.id = p.notebook_id
      WHERE nb.id = #id#
      </select>

      Do to the left join this query will always result in at least one page being created even though the pages are actually empty.
      It would be nice if the mapping framework could somehow not create these empty objects.
      The following suggestions come to mind:
      Either do not create objects where all parameters are null (this indicates the left or right join scenario)
      or provide a way to tag a property in the resultMap which may not be null in order for the object to be created.
      Example:
      <resultMap class="page" groupBy="id" id="pageResult">
      <result column="P_ID" jdbcType="VARCHAR" property="id" doNotCreateOnNull="true"/>
      </resultMap>
      This would greatly ease the use of complex mappings where one wants to prevent the dreaded N+1 Select Problem.

      Attachments

        1. BasicResultMap.java
          23 kB
          Sylvain Laurent
        2. BasicResultMapping.java
          5 kB
          Sylvain Laurent
        3. iBATIS-375.patch
          6 kB
          Ian Zabel
        4. sql-map-2.dtd
          14 kB
          Sylvain Laurent
        5. SqlMapParser.java
          26 kB
          Sylvain Laurent

        Issue Links

          Activity

            People

              Unassigned Unassigned
              musk Stefan Langer
              Votes:
              9 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: