You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Okku Touronen <ok...@stendahls.net> on 2006/03/30 12:39:52 UTC

resultMapping question

Hello.

 

If I have a class Rectangle containing two Point objects like this:

 

class R

{

            int id;

P p1;

            P p2;

}

 

 

class P

{

            int id;

            int x;

            int y;

}

 

 

I can do like this to query for rectangles:

 

select r.id as r_id, 

p1.id as p1_id, p1.x as p1_x, p1.y as p1_y,

p2.id as p2_id, p2.x as p2_x, p2.y as p2_y

from R r

inner join P p1 on R.p1_id = p1.id

inner join P p2 on R.p2_id = p2.id

 

with 3 result maps like this:

 

<resultMap id="R-result" class="R">

            <result property="id" column="id" />

            <result property="p1" resultMapping="p1-result" />

            <result property="p2" resultMapping="p2-result" />

</resultMap>

 

<resultMap id="p1-result" class="P">

            <result property="id" column="p1_id" />

            <result property="x" column="p1_x" />

            <result property="y" column="p1_y" />

</resultMap>

 

<resultMap id="p2-result" class="P">

            <result property="id" column="p2_id" />

            <result property="x" column="p2_x" />

            <result property="y" column="p2_y" />

</resultMap>

 

And now to the questions:

Is there a better way to express this?

 

I would like to express it something like this instead:

 

<resultMap id="R-result" class="R">

            <result property="id" column="id" />

            <result property="p1" resultMapping="p-result"
columnPrefix="p1_"/>

            <result property="p2" resultMapping="p-result"
columnPrefix="p2_"/>

</resultMap>

 

<resultMap id="p-result" class="P">

            <result property="id" column="id" />

            <result property="x" column="x" />

            <result property="y" column="y" />

</resultMap>

 

Is this possible? Have I missed something?

 

Reagrds Okku Touronen

 

 

PS. The examples is just pseudo code and can contain syntactical errors.


Re: resultMapping question

Posted by Gilles Bayon <ib...@gmail.com>.
Your suggestion
<result property="p1" resultMapping="p-result" columnPrefix="p1_"/>
is not possible but feasible, you could open a Jira improvement ticket

For now I don't see an other solution than first.

-Cheers
Gilles