UnsupportedOperationException on query

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

UnsupportedOperationException on query

Jason Bennett
I'm seeing this stack trace with MyBatis 3.1.1. The query has a foreach element in it, but it's not clear what I did wrong to cause this:

Caused by: java.lang.UnsupportedOperationException
        at org.apache.ibatis.reflection.wrapper.CollectionWrapper.get(CollectionWrapper.java:34)
        at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:123)
        at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextMap.get(DynamicContext.java:89)
        at org.apache.ibatis.builder.xml.dynamic.DynamicContext$ContextAccessor.getProperty(DynamicContext.java:107)
        at org.apache.ibatis.ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1657)
        at org.apache.ibatis.ognl.ASTProperty.getValueBody(ASTProperty.java:92)
        at org.apache.ibatis.ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
        at org.apache.ibatis.ognl.SimpleNode.getValue(SimpleNode.java:210)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:333)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:413)
        at org.apache.ibatis.ognl.Ognl.getValue(Ognl.java:395)
        at org.apache.ibatis.builder.xml.dynamic.OgnlCache.getValue(OgnlCache.java:42)
        at org.apache.ibatis.builder.xml.dynamic.ExpressionEvaluator.evaluateIterable(ExpressionEvaluator.java:43)
        at org.apache.ibatis.builder.xml.dynamic.ForEachSqlNode.apply(ForEachSqlNode.java:51)
        at org.apache.ibatis.builder.xml.dynamic.MixedSqlNode.apply(MixedSqlNode.java:29)
        at org.apache.ibatis.builder.xml.dynamic.DynamicSqlSource.getBoundSql(DynamicSqlSource.java:37)
        at org.apache.ibatis.mapping.MappedStatement.getBoundSql(MappedStatement.java:241)
        at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:79)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101)
        ... 62 more

Reply | Threaded
Open this post in threaded view
|

Re: UnsupportedOperationException on query

Eduardo Macarron
Hi Jason, please post the statement and the types of the objects you are using.
Reply | Threaded
Open this post in threaded view
|

Re: UnsupportedOperationException on query

Jason Bennett
I believe it was caused by my passing Sets into the MyBatis mappers rather than lists, as changing this fixed the problem. Otherwise, I'm using a standard foreach construct straight out of the docs.

jason

On Wednesday, June 20, 2012 8:56:57 PM UTC-7, Eduardo wrote:
Hi Jason, please post the statement and the types of the objects you are using.
Reply | Threaded
Open this post in threaded view
|

Re: UnsupportedOperationException on query

pnikos
This post has NOT been accepted by the mailing list yet.
Hi, I have a simple app in Java that uses MyBatis to read from a db table. The xml part that reads the item ids is the following:
<select id="readItemIds" parameterType="list" resultType="list">
select
itemId
from
tItem
where
itemGrp in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
'#{item}'
</foreach>
</select> 

If the field itemGrp in the database is numeric everything works fine. However if it is VARCHAR (and it has to be), then I get the following:
Exception handled:
org.springframework.jdbc.UncategorizedSQLException :
### Error querying database. Cause: java.sql.SQLException: Number of input values does not match number of question marks
### The error may exist in com/items/dao/GetItemsMybatis.xml
### The error may involve com.items.dao.GetItemsMybatis.readItemIds-Inline
### The error occurred while setting parameters
### SQL: select itemId from tItem where itemGrp in ( ? , ? , ? , ? )
### Cause: java.sql.SQLException: Number of input values does not match number of question marks
; uncategorized SQLException for SQL []; SQL state [IX000]; error code [-79749]; Number of input values does not match number of question marks; nested exception is java.sql.SQLException: Number of input values does not match number of question marks
at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:84)
at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackS QLExceptionTranslator.translate(AbstractFallbackSQ LExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.tran slateExceptionIfPossible(MyBatisExceptionTranslato r.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionIn terceptor.invoke(SqlSessionTemplate.java:371)
at com.sun.proxy.$Proxy82.selectList(Unknown Source)

The Database I am using is Informix. The list I am sending to the query is an ArrayList of 4 Strings.

Any ideas?
Nikos