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 Nguyen Trong Hoan <ho...@vips.com.vn> on 2007/01/23 01:07:31 UTC

Complex properties and substitution strings parameter problem

Hi!

I'm developing a web app with ibatis (2.2) and have got a problem with 
complex properties and passing substitution strings parameter for sql query 
of properties.

For example:

<sqlMap namespace="user">
    <resultMap id="User" class="bean.User">
        <result property="id" column="id"  />
        <result property="name" column="name" />
        <result property="address" column="id" select="getAddress"/>
    </resultMap>

    <select id="getUser" parameterClass="int"  resultMap="User">
        SELECT id,name FROM $schema$.tbl_user WHERE id = #value#
    </select>

    <select id="getAddress" parameterClass="int" resultClass="string">
        SELECT address FROM $schema$.tbl_address WHERE id = #value#
    </select>
</sqlMap>

Here, bean.User class is declared as the following:
public class User {
    private String schema;
    private int id;
    private String name;
}

so, I only passed schema parameter for getUser sql, but I couldn't pass it 
for getAddress sql.
Please help me to solve this problem.
Thank you very much!

Re: Complex properties and substitution strings parameter problem

Posted by Jeff Butler <je...@gmail.com>.
Both properties will need to be available in your parameter class - so "int"
won't work.  Try "map" as the parameter class, then pass a HashMap:

Map parms = new HashMap();
parms.put("schema", "mySchema");
parms.put("id", id);

User user = (User) sqlMap.queryForObject("getUser", parms);

The SQL map looks like this:
   <select id="getUser" parameterClass="map"  resultMap="User">
        SELECT id,name FROM $schema$.tbl_user WHERE id = #id#
    </select>

Jeff Butler




On 1/22/07, Nguyen Trong Hoan <ho...@vips.com.vn> wrote:
>
>  Hi!
>
> I'm developing a web app with ibatis (2.2) and have got a problem with
> complex properties and passing substitution strings parameter for sql query
> of properties.
>
> For example:
>
> <sqlMap namespace="user">
>     <resultMap id="User" class="bean.User">
>         <result property="id" column="id"  />
>         <result property="name" column="name" />
>         <result property="address" column="id" select="getAddress"/>
>     </resultMap>
>
>     <select id="getUser" parameterClass="int"  resultMap="User">
>         SELECT id,name FROM $schema$.tbl_user WHERE id = #value#
>     </select>
>
>     <select id="getAddress" parameterClass="int" resultClass="string">
>         SELECT address FROM $schema$.tbl_address WHERE id = #value#
>     </select>
> </sqlMap>
>
> Here, *bean.User* class is declared as the following:
> public class User {
>     private String schema;
>     private int id;
>     private String name;
> }
>
> so, I only passed *schema* parameter for *getUser *sql, but I couldn't
> pass it for *getAddress* sql.
> Please help me to solve this problem.
> Thank you very much!
>
>