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 "Chen, Tim" <Ti...@NielsenMedia.com> on 2005/01/05 20:22:52 UTC

Incorrect usage of n+1 fix?

Following the threads on the mailing list archive I tried to use the n+1 fix but I get the following from my query.
Below is the exception and the related items that I have defined.
It's interesting to note that if I don't try to execute getQuartersForServiceYear then it works fine (doesn't complain about missing maps etc).

Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named monthMap in this SqlMap.
com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in sqlMap.xml.
 
  <resultMap id="quarterMap" class="calendarQuarter">
    <result property="quarter" column="quarter"/>
    <result property="name" column="name"/>
    <result property="description" column="description"/>
    <result property="months" resultMap="monthMap"/>
  </resultMap>
 
  <resultMap id="monthMap" class="calendarMonth" groupBy="name">
    <result property="name" column="monthName"/>
    <result property="description" column="monthDescription"/>
    <result property="broadcastStartDate" column="broadcastStartDate"/>
    <result property="broadcastEndDate" column="broadcastEndDate"/>
  </resultMap>
 
  <select id="getQuartersForServiceYear" resultMap="quarterMap">
    select
        distinct $serviceCode$QuarterNumber as quarter,
        $serviceCode$QuarterName as name,
        $serviceCode$QuarterDesc as description,
        $serviceCode$SeasonYear as year,
        $serviceCode$MonthName as monthName,
        $serviceCode$MonthDesc as monthDescription,
        min(broadcastDate) as broadcastStartDate,
        max(broadcastDate) as broadcastEndDate
    from BroadcastDate
    where $serviceCode$SeasonYear = #year#
    and $serviceCode$MonthName is not null
    group by
        $serviceCode$QuarterDesc,
        $serviceCode$QuarterNumber,
        $serviceCode$QuarterName,
        $serviceCode$SeasonYear,
        $serviceCode$MonthName,
        $serviceCode$MonthDesc
    order by broadcastStartDate
  </select>


Re: Incorrect usage of n+1 fix?

Posted by Michal Malecki <mi...@poczta.onet.pl>.
Incorrect usage of n+1 fix?Shouldn't groupBy="name" be rather in the quarterMap? It is there, where the grouping happens.
Michal Malecki

  Following the threads on the mailing list archive I tried to use the n+1 fix but I get the following from my query. 
  Below is the exception and the related items that I have defined. 
  It's interesting to note that if I don't try to execute getQuartersForServiceYear then it works fine (doesn't complain about missing maps etc).

  Caused by: com.ibatis.sqlmap.client.SqlMapException: There is no result map named monthMap in this SqlMap.
  com.ibatis.common.jdbc.exception.NestedSQLException:
  --- The error occurred in sqlMap.xml.
   
    <resultMap id="quarterMap" class="calendarQuarter">
      <result property="quarter" column="quarter"/>
      <result property="name" column="name"/>
      <result property="description" column="description"/>
      <result property="months" resultMap="monthMap"/>
    </resultMap>
   
    <resultMap id="monthMap" class="calendarMonth" groupBy="name">
      <result property="name" column="monthName"/>
      <result property="description" column="monthDescription"/>
      <result property="broadcastStartDate" column="broadcastStartDate"/>
      <result property="broadcastEndDate" column="broadcastEndDate"/>
    </resultMap>
   
    <select id="getQuartersForServiceYear" resultMap="quarterMap">
      select
          distinct $serviceCode$QuarterNumber as quarter,
          $serviceCode$QuarterName as name,
          $serviceCode$QuarterDesc as description,
          $serviceCode$SeasonYear as year,
          $serviceCode$MonthName as monthName,
          $serviceCode$MonthDesc as monthDescription,
          min(broadcastDate) as broadcastStartDate,
          max(broadcastDate) as broadcastEndDate
      from BroadcastDate
      where $serviceCode$SeasonYear = #year#
      and $serviceCode$MonthName is not null
      group by
          $serviceCode$QuarterDesc,
          $serviceCode$QuarterNumber,
          $serviceCode$QuarterName,
          $serviceCode$SeasonYear,
          $serviceCode$MonthName,
          $serviceCode$MonthDesc
      order by broadcastStartDate
    </select>