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 Luis Duran <el...@cantv.net> on 2006/05/06 16:54:35 UTC

Problems using iterate when list is a parameterClass property

Hello, 

 

I’m trying this:

 

    <select id="findUser" resultMap="userResult" parameterClass="user" >

        select

            u.userId,

            passwd,

            fullname

        from WEB2_Users as u 

                inner join WEB2_UsersRoles as ur

                        on u.userId = ur.userId

        <dynamic prepend="where">

            <isNotEmpty prepend="and" property="userId">

                u.userId like #userId:VARCHAR#

            </isNotEmpty>

                <isNotEmpty property="roles" prepend="and">

                        ur.roleId in 

                        <iterate open="(" close=")" conjunction=",">

                            #roles[].id#

                        </iterate>

                </isNotEmpty>

            <isNotEmpty prepend="and" property="fullname">

                fullname like #fullname:VARCHAR#

            </isNotEmpty>

        </dynamic>

            order by fullname

    </select>

 

I’m sending the user object, it looks like this:

 

User {

            String userId, 

            String passwd,

            String fullname,

            List roles

}

 

Each property has its respectives get/set methods and are public.

 

I’m getting this:

 

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:

--- The error occurred in properties/sql/Account.xml.

--- The error occurred while preparing the mapped statement for execution.

--- Check the findUser.

--- Check the parameter map.

--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or
property was not a Collection, Array or Iterator.

Caused by: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or
property was not a Collection, Array or Iterator.

 

I’m using: iBatis within a webapp running on tomcat on linux, j2sdk 1.5.0_06

 

This is the only problem I found using iBatis so far, the rest is working
pretty nice.

 

Could you give me some hint? Is it possible what I am trying to do? Thanks
in advanced and sorry about my English.

 

 

Luis Edgardo Durán Lebis

Sistemas y Soporte Técnico

http://www.elebis.net/

elebis@cantv.net

 

 


Re: Problems using iterate when list is a parameterClass property

Posted by Zarar Siddiqi <za...@utoronto.ca>.
It's not the parameter class that's the problem, it's the way you are using 
<iterate>.  Since you're not specifying the "property" attribute in the 
iterate tag, it's trying to interpret the "user" parameter as a collection 
or list which it obviously isn't.

You need to explicitly specify what the property you want to iterate over 
is.  Like this:

<iterate open="(" close=")" conjunction="," property="roles"">

Zarar Siddiqi



----- Original Message ----- 
From: Luis Duran
To: user-java@ibatis.apache.org
Sent: Saturday, May 06, 2006 10:54 AM
Subject: Problems using iterate when list is a parameterClass property


Hello,

I'm trying this:

    <select id="findUser" resultMap="userResult" parameterClass="user" >
        select
            u.userId,
            passwd,
            fullname
        from WEB2_Users as u
                inner join WEB2_UsersRoles as ur
                        on u.userId = ur.userId
        <dynamic prepend="where">
            <isNotEmpty prepend="and" property="userId">
                u.userId like #userId:VARCHAR#
            </isNotEmpty>
                <isNotEmpty property="roles" prepend="and">
                        ur.roleId in
                        <iterate open="(" close=")" conjunction=",">
                            #roles[].id#
                        </iterate>
                </isNotEmpty>
            <isNotEmpty prepend="and" property="fullname">
                fullname like #fullname:VARCHAR#
            </isNotEmpty>
        </dynamic>
            order by fullname
    </select>

I'm sending the user object, it looks like this:

User {
            String userId,
            String passwd,
            String fullname,
            List roles
}

Each property has its respectives get/set methods and are public.

I'm getting this:

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:
--- The error occurred in properties/sql/Account.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the findUser.
--- Check the parameter map.
--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or 
property was not a Collection, Array or Iterator.
Caused by: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or 
property was not a Collection, Array or Iterator.

I'm using: iBatis within a webapp running on tomcat on linux, j2sdk 1.5.0_06

This is the only problem I found using iBatis so far, the rest is working 
pretty nice.

Could you give me some hint? Is it possible what I am trying to do? Thanks 
in advanced and sorry about my English.


Luis Edgardo Durán Lebis
Sistemas y Soporte Técnico
http://www.elebis.net/
elebis@cantv.net