ibatis v2.0 - Element type "iterate" must be followed by either attrib ute specifications, ">" or "/>"

1,334 views
Skip to first unread message

allter...@netzero.net

unread,
Dec 3, 2010, 12:53:33 AM12/3/10
to mybati...@googlegroups.com
Hi Christian, *,

My matchClass is a complex class with two array members
List<String> idList
List<Element> elementList (each element has Sting elementName and String elementAlias)
1. I tried List and Array implementations but both hit the same exception as follows:

Element type "iterate" must be followed by either attribute specifications, ">" or "/>".

2. Does v2 support parameterClass that is other than java.util.List?

3. In addition to List, does v2 allow Array to be passed in?

4 If v2 supports Java List only, how do I pass in a complex class?

5. This is my new sqlMapping. Anything I miss?

---
<select id="get_id_from_element_info" resultClass="java.lang.String"
parameterClass="com.abc.matchClass">
SELECT id
FROM element_info
WHERE
id IN (SELECT id
FROM association
WHERE
<iterate property="elementList" open="(" separator="OR" close=")">
(elementName =
#elementList[].elementName#} AND (elementAlias= #elementList[].elementAlias#})
</iterate>
))
<isNotEmpty prepend="AND" property="idList">
<iterate prepend="id IN " property="idList" open="(" close=")" conjunction=",">
#idList[]#
</iterate>
</isNotEmpty>
;
</select>

Thanks,

- Z
---------- Original Message ----------
From: Poitras Christian <Christia...@ircm.qc.ca>
To: "'mybati...@googlegroups.com'" <mybati...@googlegroups.com>
Subject: RE: Cause: org.xml.sax.SAXParseException: Element type "if" must be declared.
Date: Thu, 2 Dec 2010 08:39:09 -0500

Hi,

What version of MyBatis do you use?
Your code seems like a mix of MyBatis 2 and MyBatis 3.
If you use MyBaits 2, <if> and <foreach> don't exists. You should use things like <isEqual> and <iterate> instead.

Christian

-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Z
Envoyé : December-01-10 4:58 PM
À : mybati...@googlegroups.com
Objet : Cause: org.xml.sax.SAXParseException: Element type "if" must be declared.


Howdy!

My java code has a matchClass with two arrays like following
String[] idArray;
Element[] elementArray; // Element is a class with two String members
- elementName and elementAlias

This is my sqlMapping.

<select id="get_id_from_element_info" resultClass="java.lang.String"
parameterClass="com.abc.matchClass">
SELECT id
FROM element_info
WHERE
<if test="idArray.length > 0">
id IN
<foreach item="idItem" index="index" collection="idArray"
open="(" separator="," close=")">
#{idItem}
</foreach>
AND
</if>
id IN (SELECT id
FROM association
WHERE
<foreach item="item" index="index"
collection="elementArray" open="(" separator="OR" close=")">
(elementName =
#{item.elementName} AND elementAlias= "#{item.elementAlias})
</foreach>
));
</select>

I hit the following run-time error message.

exception: java.lang.RuntimeException: Error occurred. Cause:
com.ibatis.common.xml.NodeletException: Error parsing XML. Cause:
java.lang.RuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.
Cause: com.ibatis.common.xml.NodeletException: Error parsing XML. Cause:
org.xml.sax.SAXParseException: Element type "if" must be declared.

Also, if I remove the entire "<if...> ...</if>" block, I hit a similar
exception - Element type "foreach" must be declared.

Do I miss something here? Any hit or suggestion?

Thank you in advanced.


-Z


--
View this message in context: http://mybatis-user.963551.n3.nabble.com/Cause-org-xml-sax-SAXParseException-Element-type-if-must-be-declared-tp2002444p2002444.html
Sent from the mybatis-user mailing list archive at Nabble.com.

____________________________________________________________
Moms Asked to Return to School
Grant Funding May Be Available to Those That Qualify.
http://thirdpartyoffers.netzero.net/TGL3231/4cf88647ee3624dbb5dst03vuc

Poitras Christian

unread,
Dec 3, 2010, 7:48:50 AM12/3/10
to mybati...@googlegroups.com
Hi,

1. I am not sure about the exception you get. I've never seen it myself... Maybe it's because you use separator rather than conjunction in the first <iterate>.
2. I recommend you to never use java.util.List as a parameterClass with iterate - prefer map or some other object. I've seen people having troubles with List as a parameter but all was well when they put their List in a Map (thus having parameterClass="map").
3. I think it supports arrays. I haven't used it for some time so I am not sure.
4. You can pass a complex class as a parameter. If you need to pass many parameters, put them in a map and use parameterClass="map".
5. Your query looks good to me except for the "separator" attribute in the first <iterate>.

Btw, are you beginning a new project? If so, I strongly recommend you to use MyBatis 3 as it corrects many troubles I had with version 2, especially with discriminators.

Christian

-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de allter...@netzero.net
Envoyé : December-03-10 12:54 AM
À : mybati...@googlegroups.com
Objet : ibatis v2.0 - Element type "iterate" must be followed by either attrib ute specifications, ">" or "/>"

Reply all
Reply to author
Forward
0 new messages