[ibatis]列名无效问题处理

问题场景:
使用了ibatis的查询功能,点击查询后一直报列名无效的问题,但是将日志中打印出来的sql在pl/sql里面执行没有报错。检查了ibatis的sql管理文件,列名没有写错的情况,参数传递也正确。

问题原因:
ibatis会自动缓存查询语句的列的映射关系,如果在某个查询里面使用了动态sql,就有可能在查询的时候报列名无效的异常。比如以下SQL:

<select id="getFixedDepositNoSQL" parameterClass="java.util.HashMap" resultClass="java.util.HashMap">
        <isEqual property="nTypeID" compareValue="1" prepend="">
            <include refid="fixedDepositnTypeID1" ></include>
        </isEqual>
        <isEqual property="nTypeID" compareValue="22" prepend="">
            <include refid="fixedDepositnTypeID22and21" ></include>
        </isEqual>
        <isEqual property="nTypeID" compareValue="21" prepend="">
            <include refid="fixedDepositnTypeID22and21" ></include>
        </isEqual>
        <isEqual property="nTypeID" compareValue="3" prepend="">
            <include refid="fixedDepositnTypeID3" ></include>
        </isEqual>
</select>

解决办法,在动态SQL里面添加remapResults=”true”属性,让ibatis每次都重新映射这个sql的列名:

<select id="getFixedDepositNoSQL" parameterClass="java.util.HashMap" resultClass="java.util.HashMap" remapResults="true">

以上,参考自:
http://www.cnblogs.com/ding0910/archive/2011/07/12/2104374.html
感谢原作者。

猜你喜欢

转载自blog.csdn.net/yang_lover/article/details/54316680
今日推荐