ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Barry <pauljbar...@gmail.com>
Subject Re: using #value[]#
Date Thu, 09 Jun 2005 20:25:48 GMT
Oops.  I did move it inside the iterate tag where it belongs, but that
didn't fix my problem, still same exception as before.

On 6/9/05, Daniel Henrique Ferreira e Silva <dhsilva@gmail.com> wrote:
> Hi Paul,
> 
> Did you try putting session_id IN #value[]# inside iterate tag?
> 
> Cheers,
> Daniel Silva.
> 
> On 6/9/05, Paul Barry <pauljbarry3@gmail.com> wrote:
> > I am using iBatis 2.1.0.565 with JDK 1.5.0.  I am trying to pass a
> > List to a sqlmap and then use it to generate a list of comma-separated
> > values for the IN clause of a query, like this:
> >
> >   <resultMap id="counts" class="map">
> >     <result property="id" column="id" javaType="long"/>
> >     <result property="count" column="count" javaType="int"/>
> >   </resultMap>
> >
> >   <select id="findCountsBySession" parameterClass="list" resultMap="counts">
> >     SELECT
> >       session_id as id, count(*) count
> >     FROM
> >       events
> >     <dynamic prepend="WHERE">
> >         <iterate property="value" open="(" close=")" conjunction=",">
> >         </iterate>
> >       session_id IN #value[]#
> >     </dynamic>
> >     GROUP BY
> >       session_id
> >   </select>
> >
> > The query I would like to end up with is:
> >
> > SELECT
> >   session_id, count(*) count
> > FROM
> >   events
> > WHERE
> >   session_id IN (1,2,3)
> > GROUP BY
> >   session_id
> >
> > But instead I get an exception.  Can you not use #value[]#?  Here is
> > the exception:
> >
> > java.lang.StringIndexOutOfBoundsException: String index out of range: -2
> >         at java.lang.String.substring(String.java:1768)
> >         at com.ibatis.common.beans.GenericProbe.getObject(GenericProbe.java:55)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.elements.IterateTagHandler.doStartFragment(IterateTagHandler.java:34)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:129)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:132)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.processBodyChildren(DynamicSql.java:99)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.process(DynamicSql.java:79)
> >         at com.ibatis.sqlmap.engine.mapping.sql.dynamic.DynamicSql.getParameterMap(DynamicSql.java:61)
> >         at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryWithCallback(GeneralStatement.java:152)
> >         at com.ibatis.sqlmap.engine.mapping.statement.GeneralStatement.executeQueryForList(GeneralStatement.java:119)
> >         at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:610)
> >         at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:584)
> >         at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForMap(SqlMapExecutorDelegate.java:700)
> >         at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForMap(SqlMapSessionImpl.java:121)
> >         at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForMap(SqlMapClientImpl.java:93)
> >
>

Mime
View raw message