ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jeff Butler" <jeffgbut...@gmail.com>
Subject Re: Complex properties and substitution strings parameter problem
Date Tue, 23 Jan 2007 00:37:45 GMT
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 <hoannt8047@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!
>
>

Mime
View raw message