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 Karen Koch <km...@sbcglobal.net> on 2005/05/23 19:12:37 UTC
Recommended practice / nested ResultMaps
Given the following nested resultMap configuration with the child resultMap including a complex property that is part of the groupBy, how should the groupBy on that property be specified? I tried using the complex property name, and I tried qualifying the complex property name with the simple key-value sub-property -- neither worked properly.
<resultMap id="distUsagesResult" class="distUsages" groupBy="distKey, entryDate">
<result property="distKey" column="DistKey"/>
<result property="entryDate" column="Date"/>
<result property="org" column="Org"/>
<result property="costCtr" column="CostCtr"/>
<result property="task" column="Task"/>
<result property="option" column="Option"/>
<result property="statisticList" resultMap="StatType.statisticResult"/>
</resultMap>
<resultMap id="statisticResult" class="statistic" groupBy="distKey, entryDate, statType">
<!-- also tried <resultMap id="statisticResult" class="statistic" groupBy="distKey, entryDate, statType.statTypeKey"> -->
<result property="distKey" column="StatDistKey"/>
<result property="entryDate" column="StatEntryDate"/>
<result property="statType" column="StatTypeKey" select="getStatType"/>
<result property="numUnits" column="StatNumUnits"/>
</resultMap>
<resultMap id="statTypeResult" class="statType">
<result property="statTypeKey" column="StatTypeKey"/>
<result property="statTypeID" column="StatTypeID"/>
<result property="statTypeDesc" column="StatTypeDesc"/>
<result property="measUnits" column="MeasUnits"/>
<result property="numDecPlaces" column="NumDecPlaces"/>
<result property="org" column="Org"/>
<result property="account" column="Account"/>
<result property="costCtr" column="CostCtr"/>
<result property="task" column="Task"/>
<result property="option" column="Option"/>
</resultMap>
Thanks thanks thanks!
Karen
Re: Recommended practice / nested ResultMaps
Posted by Clinton Begin <cl...@gmail.com>.
When you say "neither worked properly", what do you mean? Did you get an
exception? Or did you just get unexpected results?
Did you override both equals() and hashCode() for the complex property type?
As per the standard? Here's a description of how to override them properly:
http://www.geocities.com/technofundo/tech/java/equalhash.html
Cheers,
Clinton
On 5/23/05, Karen Koch <km...@sbcglobal.net> wrote:
>
> Given the following nested resultMap configuration with the child
> resultMap including a complex property that is part of the groupBy, how
> should the groupBy on that property be specified? I tried using the complex
> property name, and I tried qualifying the complex property name with the
> simple key-value sub-property -- neither worked properly.
> <resultMap id="distUsagesResult" class="distUsages" groupBy="distKey,
> entryDate">
> <result property="distKey" column="DistKey"/>
> <result property="entryDate" column="Date"/>
> <result property="org" column="Org"/>
> <result property="costCtr" column="CostCtr"/>
> <result property="task" column="Task"/>
> <result property="option" column="Option"/>
> <result property="statisticList" resultMap="StatType.statisticResult"/>
> </resultMap>
> <resultMap id="statisticResult" class="statistic" groupBy="distKey,
> entryDate, statType">
> <!-- also tried <resultMap id="statisticResult" class="statistic"
> groupBy="distKey, entryDate, statType.statTypeKey"> -->
> <result property="distKey" column="StatDistKey"/>
> <result property="entryDate" column="StatEntryDate"/>
> <result property="statType" column="StatTypeKey" select="getStatType"/>
> <result property="numUnits" column="StatNumUnits"/>
> </resultMap>
> <resultMap id="statTypeResult" class="statType">
> <result property="statTypeKey" column="StatTypeKey"/>
> <result property="statTypeID" column="StatTypeID"/>
> <result property="statTypeDesc" column="StatTypeDesc"/>
> <result property="measUnits" column="MeasUnits"/>
> <result property="numDecPlaces" column="NumDecPlaces"/>
> <result property="org" column="Org"/>
> <result property="account" column="Account"/>
> <result property="costCtr" column="CostCtr"/>
> <result property="task" column="Task"/>
> <result property="option" column="Option"/>
> </resultMap>
> Thanks thanks thanks!
> Karen
>