ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Todd Wilkinson" ...@dealsqueal.com>
Subject Problem iterating over a list of beans
Date Tue, 08 Jul 2008 20:53:21 GMT

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       my.package.QueryCondition@1f5b4d1
my.package.QueryCondition@1f5b4d1 ?

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!


Mime
View raw message