Getting error while iterating Map in mybatis

707 Views Asked by At

Getting this error while iterating over Map in mybatis

Cause: org.apache.ibatis.type.TypeException: Could not set parameters for mapping: ParameterMapping{property='__frch_key_0', mode=IN, javaType=class java.util.UUID, jdbcType=null, numericScale=null, resultMapId='null', jdbcTypeName='null', expression='null'}. Cause: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 with JdbcType null . Try setting a different JdbcType for this parameter or a different configuration property. Cause: org.postgresql.util.PSQLException: The column index is out of range: 1, number of columns: 0.

Mapper method

int updateUser(@Param("params") Map<UUID, UUID> params);

query

<update id="updateUser">
        UPDATE users AS u
        SET role_id = CAST(p.roleid AS uuid)
        FROM (VALUES
        <foreach collection="params" item="item" index="index"  open="('" separator="'),('" close="')">
            #{index} ',' #{item} 
        </foreach>
        )
        AS p(user_id ,roleid)
        WHERE CAST(p.user_id AS uuid) = u.user_id
    </update>
1

There are 1 best solutions below

0
On

I solved the issue by replacing the #{index} #{item} to ${index} ${item}. May be foreach works different map type.