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 "Eric T. Blue" <er...@gmail.com> on 2005/05/12 01:14:23 UTC

Referencing a select statement or resultmap in another config file

Hi,

I have a number of objects/tables that require mapping, and in many 
instances there are 1-many relationships.  In order to minimize 
duplication in the config files, I would like to be able to reference a 
select statement in another namespace/config file.  For example:

// File 1

<sqlMap namespace="Object1">

    <resultMap id="object1Result" class="com.ericblue.domain.Object1">
        <result property="id" column="id"/>
        <result property="name" column="name"/>         
        <result property="someList" column="id" 
select="Object2.getSomeListByObject1"/>         
    </resultMap>

</sqlMap>

// File 2

<sqlMap namespace="Object2">

    <resultMap id="object2Result" class="com.ericblue.domain.Object2">
        <result property="id" column="id"/>
        <result property="name" column="name"/> 
    </resultMap>

    <select id="getSomeListByObject1" resultMap="object2Result">
       select * from some_table where id = #id#
     </select>

</sqlMap>

Any help is appreciated!




Re: Referencing a select statement or resultmap in another config file

Posted by "Eric T. Blue" <er...@gmail.com>.
Argh, nevermind.  It helps if I actually check my select statement 
spelling between configs before I post to the mailing list. ;)  All is well.

Eric T. Blue wrote:

> Hi,
>
> I have a number of objects/tables that require mapping, and in many 
> instances there are 1-many relationships.  In order to minimize 
> duplication in the config files, I would like to be able to reference 
> a select statement in another namespace/config file.  For example:
>
> // File 1
>
> <sqlMap namespace="Object1">
>
>    <resultMap id="object1Result" class="com.ericblue.domain.Object1">
>        <result property="id" column="id"/>
>        <result property="name" column="name"/>                <result 
> property="someList" column="id" 
> select="Object2.getSomeListByObject1"/>            </resultMap>
>
> </sqlMap>
>
> // File 2
>
> <sqlMap namespace="Object2">
>
>    <resultMap id="object2Result" class="com.ericblue.domain.Object2">
>        <result property="id" column="id"/>
>        <result property="name" column="name"/>    </resultMap>
>
>    <select id="getSomeListByObject1" resultMap="object2Result">
>       select * from some_table where id = #id#
>     </select>
>
> </sqlMap>
>
> Any help is appreciated!
>
>
>
>