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 DavidCAIT <dz...@cait.org> on 2009/07/08 21:14:40 UTC
IsEmpty inside Iterate Tag
Hi,
I am having trouble determining the correct syntax to use with the isEmpty
tag when iterating over a list. My program has a large list of objects with
potentially null fields and I need to customize my insert statements based
on whether or not a particular object has a certain field set to null.
Here is my SqlMap file:
<insert id="createObject" parameterClass="java.util.List">
Insert into someTable (field1, field2, field3)
Values <iterate conjunction=", ">
(#[].field1#, <isNotEmpty property="[].field2">#[].field2#,
</isNotEmpty><isEmpty property="[].field2">NULL, </isEmpty> #[].field3#)
</iterate>
</insert>
When I call this sqlMap, the isNotEmpty tag throws the following exception:
SqlMapClient operation; uncategorized SQLException for SQL []; SQL state
[null]; error code [0];
--- The error occurred in org/someFile/mySQL.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the Mapping.
--- Check the createObject parameter map.
Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list
from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index
out of range: -1; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
What syntax should I use in the isNotEmpty property field to avoid this
exception? When I remove the isNotEmpty and isEmpty tags, the sql statement
executes successfully. I tried using property="#[].field2#" and
property="field2" but neither of those statements fixed the problem.
Thanks!
--
View this message in context: http://www.nabble.com/IsEmpty-inside-Iterate-Tag-tp24397605p24397605.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
RE: IsEmpty inside Iterate Tag
Posted by DavidCAIT <dz...@cait.org>.
Yes, that did work. It seems like a bit of a waste to create a Hashmap simply
to store a duplicate of the List, but it does resolve the problem.
Thanks again for your help.
Poitras Christian wrote:
>
> Hi,
>
> Can you make it work if you put the list inside a map (under key "list")
> and use this?
>
> <insert id="createObject" parameterClass="map">
> Insert into someTable (field1, field2, field3)
> Values <iterate property="list" conjunction=", ">
> (#list[].field1#, <isNotEmpty
> property="list[].field2">#list[].field2#, </isNotEmpty><isEmpty
> property="list[].field2">NULL, </isEmpty> #list[].field3#)
> </iterate>
> </insert>
>
> Christian
>
> -----Original Message-----
> From: DavidCAIT [mailto:dzazeski@cait.org]
> Sent: Wednesday, July 08, 2009 3:15 PM
> To: user-java@ibatis.apache.org
> Subject: IsEmpty inside Iterate Tag
>
>
> Hi,
>
> I am having trouble determining the correct syntax to use with the isEmpty
> tag when iterating over a list. My program has a large list of objects
> with potentially null fields and I need to customize my insert statements
> based on whether or not a particular object has a certain field set to
> null.
>
> Here is my SqlMap file:
>
> <insert id="createObject" parameterClass="java.util.List">
> Insert into someTable (field1, field2, field3)
> Values <iterate conjunction=", ">
> (#[].field1#, <isNotEmpty property="[].field2">#[].field2#,
> </isNotEmpty><isEmpty property="[].field2">NULL, </isEmpty> #[].field3#)
> </iterate>
> </insert>
>
> When I call this sqlMap, the isNotEmpty tag throws the following
> exception:
>
> SqlMapClient operation; uncategorized SQLException for SQL []; SQL state
> [null]; error code [0];
> --- The error occurred in org/someFile/mySQL.xml.
> --- The error occurred while preparing the mapped statement for execution.
> --- Check the Mapping.
> --- Check the createObject parameter map.
> Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list
> from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String
> index out of range: -1; nested exception is
> com.ibatis.common.jdbc.exception.NestedSQLException:
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
>
> What syntax should I use in the isNotEmpty property field to avoid this
> exception? When I remove the isNotEmpty and isEmpty tags, the sql
> statement executes successfully. I tried using property="#[].field2#" and
> property="field2" but neither of those statements fixed the problem.
>
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/IsEmpty-inside-Iterate-Tag-tp24397605p24397605.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/IsEmpty-inside-Iterate-Tag-tp24397605p24398389.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
RE: IsEmpty inside Iterate Tag
Posted by Poitras Christian <Ch...@ircm.qc.ca>.
Hi,
Can you make it work if you put the list inside a map (under key "list") and use this?
<insert id="createObject" parameterClass="map">
Insert into someTable (field1, field2, field3)
Values <iterate property="list" conjunction=", ">
(#list[].field1#, <isNotEmpty property="list[].field2">#list[].field2#, </isNotEmpty><isEmpty property="list[].field2">NULL, </isEmpty> #list[].field3#)
</iterate>
</insert>
Christian
-----Original Message-----
From: DavidCAIT [mailto:dzazeski@cait.org]
Sent: Wednesday, July 08, 2009 3:15 PM
To: user-java@ibatis.apache.org
Subject: IsEmpty inside Iterate Tag
Hi,
I am having trouble determining the correct syntax to use with the isEmpty tag when iterating over a list. My program has a large list of objects with potentially null fields and I need to customize my insert statements based on whether or not a particular object has a certain field set to null.
Here is my SqlMap file:
<insert id="createObject" parameterClass="java.util.List">
Insert into someTable (field1, field2, field3)
Values <iterate conjunction=", ">
(#[].field1#, <isNotEmpty property="[].field2">#[].field2#, </isNotEmpty><isEmpty property="[].field2">NULL, </isEmpty> #[].field3#)
</iterate>
</insert>
When I call this sqlMap, the isNotEmpty tag throws the following exception:
SqlMapClient operation; uncategorized SQLException for SQL []; SQL state [null]; error code [0];
--- The error occurred in org/someFile/mySQL.xml.
--- The error occurred while preparing the mapped statement for execution.
--- Check the Mapping.
--- Check the createObject parameter map.
Cause: com.ibatis.common.beans.ProbeException: Error getting ordinal list from JavaBean. Cause java.lang.StringIndexOutOfBoundsException: String index out of range: -1; nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
What syntax should I use in the isNotEmpty property field to avoid this exception? When I remove the isNotEmpty and isEmpty tags, the sql statement executes successfully. I tried using property="#[].field2#" and property="field2" but neither of those statements fixed the problem.
Thanks!
--
View this message in context: http://www.nabble.com/IsEmpty-inside-Iterate-Tag-tp24397605p24397605.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org