Hi- Thanks for the tip. I tried that and it didn't work. The only way I was able to get this to work was to wrap it in a class that had a property that was a list. Seems kind of kludgey - but it works nonetheless.
> I'm certainly not an expert at this, but what if instead of passing the > list > right into the query, you created a map and put the list into the map with > the key "conditions" (then pass the map into the query). > > Then, put something like this in the mapping: > > <iterate property="conditions" conjunction="and"> > $conditions[].condition$ $conditions[].operator$ #[].value# > </iterate> > > That is usually how I iterate over stuff. Not sure if I am understanding > entirely what is going on with your situation, though... > > Chris > > -----Original Message----- > From: Todd Wilkinson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, July 08, 2008 3:53 PM > To: [email protected] > Subject: Problem iterating over a list of beans > > > Hello- > I'm new to iBATIS and I'm having trouble with the <iterate> element. > > I want to create a query for an entirely dynamic where clause. I've > constructed a Bean called QueryCondition with the following properties: > > String condition > String operator > String value > > (along with public accessors and mutators) > > I'm passing an ArrayList into the following mapping: > > <select id="myObject.dynamicQuery" resultMap="myObject_resultmap" > resultClass="java.util.List"> > select id, name, data, notes > from objectTable > <dynamic prepend="where"> > <iterate conjunction="and"> > $[].condition$ $[].operator$ #[].value# > </iterate> > </dynamic> > </select> > > But it's not working. In the logs, I see the following: > Preparing Statement: select id, name, source_code_location, context, > notes from objectTable where [EMAIL PROTECTED] > [EMAIL PROTECTED] ? > > and then I get a logged exception: > 0com.ibatis.common.jdbc.exception.NestedSQLException: > --- The error occurred while applying a parameter map. > --- Check the sites.dynamicQuery-InlineParameterMap. > --- Check the parameter mapping for the '[0].value' property. > --- Cause: java.lang.NullPointerException > [full stack trace available if needed] > The line 'check the parameter mapping...' will occur for whichever one of > the properties a place in hashmarks, ie - #[].operator# will cause it > also. > > I have verified that there is 1 QueryCondition object in this list which > has its properties set. Strange that the prepared statement resolves the > first two properties to objects of type QueryCondition, instead of > property string valyes. I guess I'm not understanding how to properly > access the objects in the list. If I set a 'property' attribute in the > <iterate> tag, I get: > --- The error occurred while preparing the mapped statement for execution. > --- Check the myObject.dynamicQuery. > --- Check the parameter map. > --- Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal > list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: > String index out of range: -1 > > Thanks for any help! > > No virus found in this incoming message. > Checked by AVG. > Version: 8.0.136 / Virus Database: 270.4.6/1540 - Release Date: 7/8/2008 > 6:33 AM > >
