ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephen Hasler" <Steph...@i2.co.uk>
Subject RE: Problem with nesting resultMaps
Date Tue, 05 Feb 2008 18:03:41 GMT
Hi

 

After a session with the debugger and another trawl through the archive,
I realise this is just a repeat of the frequently occurring "Problem
with several one to many relationships in breadth" case.

 

So, please ignore it.

 

Steve

 

 

________________________________

From: Stephen Hasler [mailto:StephenH@i2.co.uk] 
Sent: 01 February 2008 17:38
To: user-java@ibatis.apache.org
Subject: Problem with nesting resultMaps

 

Hi

 

I'm having a problem mapping a 'Parent' class containing a list of
'Child'ren where both the Parent and Child types have a complex key
property. I've simplified the example to clarify the problem.

 

I can get the following mapping to work:- 

 

    <resultMap id="Parent" class="test.Parent" groupBy="key">

        <result property="key" resultMap="CRS.ParentKey" />

        <result property="children" resultMap="CRS.Child" />

    </resultMap>

 

    <resultMap id="ParentKey" class="test.ParentKey" groupBy="keyValue">

        <result property="keyValue" column="parent_key" />

    </resultMap>

 

    <resultMap id="Child" class="test.Child" groupBy="key.keyValue">

        <result property="key.keyValue" column="child_key"/>

    </resultMap>

 

However, in my real world case, the implementation, not the interface,
of the key class has the setKeyValue() method. So, I tried to split out
the Child key into a separate resultMap which should then allow me to
specify the concrete class, rather than just the interface. (This was
precisely what I did in the above mapping with the key of the Parent
class.) 

 

The mapping I thought should solve this problem is:-

 

    <resultMap id="Parent" class="test.Parent" groupBy="key">

        <result property="key" resultMap="CRS.ParentKey" />

        <result property="children" resultMap="CRS.Child" />

    </resultMap>

 

    <resultMap id="ParentKey" class="test.ParentKey" groupBy="keyValue">

        <result property="keyValue" column="parent_key" />

    </resultMap>

 

    <resultMap id="Child" class="test.Child" groupBy="key">

        <result property="key" resultMap="CRS.ChildKey"/>

    </resultMap>

 

    <resultMap id="ChildKey" class="test.ChildKey" groupBy="keyValue">

       <result property="keyValue" column="child_key" />

    </resultMap>

 

Which does not work :-(. I've tried various different combinations of
groupBy, but as far as I understand things, this is how should look.

 

Both mappings versions are used by the same select statement which is:-

 

    <select id="SelectByKeyValue" parameterClass="String"
resultMap="Parent">

    SELECT p.key parent_key, c.key child_key

      FROM parents p, children c

     WHERE p.parent_key = #id#

       AND p.parent_key = c.parent_key

    </select>

 

Can anybody explain to me what I'm doing wrong?

 

Thanks for you patience.

 

Steve

 

 

________________________________



The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.





-----------------------------------------
The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.
Mime
View raw message