Nested Select: how to pass map values around together with column value ?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Nested Select: how to pass map values around together with column value ?

PierreR
Following the documentation I can easily pass a column value from one
select to another. But how can I pass parameters knows in the previous
select ?

To explain what I mean, here is a simple example:

<select id=”selectBlog” resultMap="blogResult"
parameterType="java.util.Map">
        SELECT
        id,
        <if test="lang=='fr'">
           nameFR name
        </if>
        <if test="lang=='nl'">
           namenNL as name
        </if>
  FROM PERSON WHERE ID = #{id}
</select>

<select id=”selectAuthor”>
        SELECT
        id,
  <if test="lang=='fr'">
       nameFR name
        </if>
        <if test="lang=='nl'">
           namenNL as name
        </if>
 WHERE ID = #{id}
</select>

<resultMap id=”blogResult” type=”Blog”>
<association property="author" column="id" javaType="Author"
select=”selectAuthor”/>
</resultMap>

In "column" of the association no only I need "id", I want "lang" as
well.

The documentation mentions nested select statement by using the syntax
column=”{prop1=col1,prop2=col2}” but "lang" is not a column of the
previous select; it is inside the parameterType="java.util.Map"

Thanks for your help,
Reply | Threaded
Open this post in threaded view
|

Re: Nested Select: how to pass map values around together with column value ?

PierreR
Hello,

I have managed the situation by passing a fake lang column in the
first select:
<select id=”selectBlog” resultMap="blogResult"
parameterType="java.util.Map">
SELECT
        id,
        <if test="lang=='fr'">
           lang = 'fr',
           nameFR name
        </if>
        <if test="lang=='nl'">
           lang = 'nl',
           namenNL as name
        </if>
        FROM PERSON WHERE ID = #{id}
</select>

<select id=”selectAuthor” parameterType="java.util.Map">
        SELECT
        id,
        <if test="lang=='fr'">
            nameFR name
        </if>
        <if test="lang=='nl'">
           namenNL as name
        </if>
 WHERE ID = #{id}
</select>

<resultMap id=”blogResult” type=”Blog”>
<association property="author"
column="{lang=lang,iddosdossier=iddosdossier}" javaType="Author"
select=”selectAuthor”/>
</resultMap>

Is this the correct way to do this ?

Thanks a million.

Cheers,

On Oct 26, 1:38 pm, PierreR <[hidden email]> wrote:

> Following the documentation I can easily pass a column value from one
> select to another. But how can I pass parameters knows in the previous
> select ?
>
> To explain what I mean, here is a simple example:
>
> <select id=”selectBlog” resultMap="blogResult"
> parameterType="java.util.Map">
>         SELECT
>         id,
>         <if test="lang=='fr'">
>            nameFR name
>         </if>
>         <if test="lang=='nl'">
>            namenNL as name
>         </if>
>         FROM PERSON WHERE ID = #{id}
> </select>
>
> <select id=”selectAuthor”>
>         SELECT
>         id,
>         <if test="lang=='fr'">
>             nameFR name
>         </if>
>         <if test="lang=='nl'">
>            namenNL as name
>         </if>
>  WHERE ID = #{id}
> </select>
>
> <resultMap id=”blogResult” type=”Blog”>
> <association property="author" column="id" javaType="Author"
> select=”selectAuthor”/>
> </resultMap>
>
> In "column" of the association no only I need "id", I want "lang" as
> well.
>
> The documentation mentions nested select statement by using the syntax
> column=”{prop1=col1,prop2=col2}” but "lang" is not a column of the
> previous select; it is inside the parameterType="java.util.Map"
>
> Thanks for your help,