美文网首页
mybatis 批量更新 【踩坑】

mybatis 批量更新 【踩坑】

作者: 醉疯觞 | 来源:发表于2017-08-17 09:59 被阅读0次

参考

星星满天

正题

数据库连接必须配置:&allowMultiQueries=true
mapper文件代码

<update id="updateMany"  parameterType="java.util.List" >
    <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            UPDATE inf_message
        <set>
            <if test="item.messageId !=null and item.messageId >= 0 "> 
                messageId = #{item.messageId},
                    </if>
            <if test="item.segment !=null and item.segment!='' ">
                 segment=#{item.segment},  
            </if> 
            <if test="item.target !=null and item.target!='' ">
                     target=#{item.target},  
            </if> 
            <if test="item.targetReal !=null and item.targetReal!='' ">
                     targetReal=#{item.targetReal},  
            </if> 
            <if test="item.appId !=null and item.appId!='' ">
                 appId=#{item.appId},  
            </if> 
            <if test="item.source !=null and item.source!='' ">
                 source=#{item.source},  
            </if> 
        </set>
            WHERE messageId = #{item.messageId}
        </foreach>    
</update>

这些都配置好后,单元测试发现还是报错

org.springframework.jdbc.UncategorizedSQLException: 
### Error updating database.  
Cause: java.sql.SQLException: Cannot execute statement: 
impossible to write to binary log since BINLOG_FORMAT = STATEMENT 
and at least one table uses a storage engine limited to row-based logging. 
InnoDB is limited to row-logging 
when transaction isolation level is READ COMMITTED or READ UNCOMMITTED.

重点在最后一句话 transaction isolation level is READ COMMITTED or READ UNCOMMITTED.
这才发现,执行该语句方法的Spring事务用的是 READ COMMITTED,用 DEFAULT 就好了

相关文章

网友评论

      本文标题:mybatis 批量更新 【踩坑】

      本文链接:https://www.haomeiwen.com/subject/pxjgrxtx.html