mybatis 批量更新 【踩坑】

参考

星星满天

正题

数据库连接必须配置:&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 就好了

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容