Reputation: 21
I'm trying to create a SelectStatement in Mybatis 3.5.13 using a foreach iterating over a map, where the keys are Column Names and the values are the value I want to select on.
I've confirmed that all keys and values are not null and are Strings.
My select query:
select * from ${tableName} where <foreach collection="dataMap.entrySet()" item="value" index="key" open=" " separator=" and " close="">
#{key} = #{value}
</foreach>
</select>
The error I'm getting is: Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_key_2', mode=IN, javaType=class java.lang.String, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #3 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: java.sql.SQLException: Invalid parameter index 3.
I tried removing the foreach and replacing it with the query I want MyBatis to create and it works as expected.
Upvotes: 1
Views: 173