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 Rashmi Dixit <ra...@gmail.com> on 2006/06/14 14:53:17 UTC
iterate over java.Util.List
Hi,
I have a select statement to which I want to attach a where clause with
an "IN". The values for the IN are BigDecimals which I would like to
pass as a java.util.List. (Note: I know this list will not be empty,
will be adding dynamic prepend later).
<select id="trial" resultMap="uploadQueueResult"
parameterClass="java.util.List">
select ID from sometable
WHERE
<iterate property="list"
open="FACILITYID in ("
close=")"
conjunction=",">
#list[]#
</iterate>
</select>
I am getting an error when I execute this
--- Check the parameter map.
--- Cause: java.lang.StringIndexOutOfBoundsException: String index out
of range: -2
What am I doing wrong here? Even if I use "value" instead of "list" as
the property value, I get the same exception. I haven't been able to
find enough iterate examples even after a google search. All examples
iterate over some property of the parameter class or a Map.
Any help will be appreciated.
Regards
~Rashmi
Re: iterate over java.Util.List
Posted by Jeff Butler <je...@gmail.com>.
You are correct Debasish - sorry for my misinformation. The docs are a
little ambiguous about this usage so I'll make it clearer - thanks!
Jeff Butler
On 6/14/06, Debasish Dutta Roy <de...@gmail.com> wrote:
>
> Hi All
> First and foremost you can surely pass the List object as a parameter. I
> have done that many times.
>
> Please do the following...
>
> List argList is your list containing all the IN values
>
> <dynamic prepend="WHERE">
> <iterate open="external_key IN(" close=")" conjunction=",">
> #[]#
> </iterate>
> </dynamic>
>
> Java code
> mapClient.queryForList ("myMethod", argList);
>
> Will sure work.
>
>
> On 6/14/06, Jeff Butler <je...@gmail.com> wrote:
> >
> > You cannot pass the list directly as the parameter object - the list
> > needs to be a property of some other object. You could put the list in a
> > map:
> >
> > Map map = new HashMap();
> > map.put("list", theList);
> >
> > then make your parameter class java.util.Map
> >
> > Jeff Butler
> >
> >
> > On 6/14/06, Rashmi Dixit <ra...@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > I have a select statement to which I want to attach a where clause
> > > with
> > > an "IN". The values for the IN are BigDecimals which I would like to
> > > pass as a java.util.List. (Note: I know this list will not be empty,
> > > will be adding dynamic prepend later).
> > >
> > > <select id="trial" resultMap="uploadQueueResult"
> > > parameterClass="java.util.List ">
> > > select ID from sometable
> > > WHERE
> > > <iterate property="list"
> > > open="FACILITYID in ("
> > > close=")"
> > > conjunction=",">
> > > #list[]#
> > > </iterate>
> > > </select>
> > >
> > > I am getting an error when I execute this
> > >
> > > --- Check the parameter map.
> > > --- Cause: java.lang.StringIndexOutOfBoundsException: String index out
> > > of range: -2
> > >
> > > What am I doing wrong here? Even if I use "value" instead of "list" as
> > > the property value, I get the same exception. I haven't been able to
> > > find enough iterate examples even after a google search. All examples
> > > iterate over some property of the parameter class or a Map.
> > >
> > > Any help will be appreciated.
> > >
> > > Regards
> > > ~Rashmi
> > >
> > >
> > >
> > >
> > >
> >
>
Re: iterate over java.Util.List
Posted by Debasish Dutta Roy <de...@gmail.com>.
Hi All
First and foremost you can surely pass the List object as a parameter. I
have done that many times.
Please do the following...
List argList is your list containing all the IN values
<dynamic prepend="WHERE">
<iterate open="external_key IN(" close=")" conjunction=",">
#[]#
</iterate>
</dynamic>
Java code
mapClient.queryForList("myMethod", argList);
Will sure work.
On 6/14/06, Jeff Butler <je...@gmail.com> wrote:
>
> You cannot pass the list directly as the parameter object - the list needs
> to be a property of some other object. You could put the list in a map:
>
> Map map = new HashMap();
> map.put("list", theList);
>
> then make your parameter class java.util.Map
>
> Jeff Butler
>
>
> On 6/14/06, Rashmi Dixit <ra...@gmail.com> wrote:
> >
> > Hi,
> >
> > I have a select statement to which I want to attach a where clause with
> > an "IN". The values for the IN are BigDecimals which I would like to
> > pass as a java.util.List. (Note: I know this list will not be empty,
> > will be adding dynamic prepend later).
> >
> > <select id="trial" resultMap="uploadQueueResult"
> > parameterClass="java.util.List ">
> > select ID from sometable
> > WHERE
> > <iterate property="list"
> > open="FACILITYID in ("
> > close=")"
> > conjunction=",">
> > #list[]#
> > </iterate>
> > </select>
> >
> > I am getting an error when I execute this
> >
> > --- Check the parameter map.
> > --- Cause: java.lang.StringIndexOutOfBoundsException: String index out
> > of range: -2
> >
> > What am I doing wrong here? Even if I use "value" instead of "list" as
> > the property value, I get the same exception. I haven't been able to
> > find enough iterate examples even after a google search. All examples
> > iterate over some property of the parameter class or a Map.
> >
> > Any help will be appreciated.
> >
> > Regards
> > ~Rashmi
> >
> >
> >
> >
> >
>
RE: iterate over java.Util.List
Posted by Rashmi Dixit <ra...@gmail.com>.
Thanks for the quick reply Jeff.
Is there some place which has all that is supported and whats not
documented somewhere? Or did I just not read the document carefully
enough?
Rashmi
_____
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: Wednesday, June 14, 2006 6:47 PM
To: user-java@ibatis.apache.org
Subject: Re: iterate over java.Util.List
You cannot pass the list directly as the parameter object - the list
needs to be a property of some other object. You could put the list in
a map:
Map map = new HashMap();
map.put("list", theList);
then make your parameter class java.util.Map
Jeff Butler
On 6/14/06, Rashmi Dixit <ra...@gmail.com> wrote:
Hi,
I have a select statement to which I want to attach a where clause with
an "IN". The values for the IN are BigDecimals which I would like to
pass as a java.util.List. (Note: I know this list will not be empty,
will be adding dynamic prepend later).
<select id="trial" resultMap="uploadQueueResult"
parameterClass="java.util.List ">
select ID from sometable
WHERE
<iterate property="list"
open="FACILITYID in ("
close=")"
conjunction=",">
#list[]#
</iterate>
</select>
I am getting an error when I execute this
--- Check the parameter map.
--- Cause: java.lang.StringIndexOutOfBoundsException: String index out
of range: -2
What am I doing wrong here? Even if I use "value" instead of "list" as
the property value, I get the same exception. I haven't been able to
find enough iterate examples even after a google search. All examples
iterate over some property of the parameter class or a Map.
Any help will be appreciated.
Regards
~Rashmi
Re: iterate over java.Util.List
Posted by Jeff Butler <je...@gmail.com>.
You cannot pass the list directly as the parameter object - the list needs
to be a property of some other object. You could put the list in a map:
Map map = new HashMap();
map.put("list", theList);
then make your parameter class java.util.Map
Jeff Butler
On 6/14/06, Rashmi Dixit <ra...@gmail.com> wrote:
>
> Hi,
>
> I have a select statement to which I want to attach a where clause with
> an "IN". The values for the IN are BigDecimals which I would like to
> pass as a java.util.List. (Note: I know this list will not be empty,
> will be adding dynamic prepend later).
>
> <select id="trial" resultMap="uploadQueueResult"
> parameterClass="java.util.List">
> select ID from sometable
> WHERE
> <iterate property="list"
> open="FACILITYID in ("
> close=")"
> conjunction=",">
> #list[]#
> </iterate>
> </select>
>
> I am getting an error when I execute this
>
> --- Check the parameter map.
> --- Cause: java.lang.StringIndexOutOfBoundsException: String index out
> of range: -2
>
> What am I doing wrong here? Even if I use "value" instead of "list" as
> the property value, I get the same exception. I haven't been able to
> find enough iterate examples even after a google search. All examples
> iterate over some property of the parameter class or a Map.
>
> Any help will be appreciated.
>
> Regards
> ~Rashmi
>
>
>
>
>