当前位置:网站首页>Mysql 批量插入事务唯一键重复处理
Mysql 批量插入事务唯一键重复处理
2022-07-30 12:11:00 【boonya】
在资源组挂靠新的资源时,由于roleId和resGroupId 是组合唯一键,所以在外部事务提交有记录的时候,当前事务提交会存在重复记录,考虑是并发操作导致。
MySQLIntegrityConstraintViolationException: Cannot add or update a child row
利用重复建更新的原理:
<insert id="bindResGroup">
INSERT INTO
`SECURITY_ROLE_RESOURCE_GROUP` (roleId, resGroupId)
VALUES
<foreach collection="resGroupIds" item="resGroupId" separator=",">
( #{roleId}, #{resGroupId})
</foreach>
ON DUPLICATE KEY UPDATE roleId = VALUES(roleId),resGroupId=VALUES(resGroupId)
</insert>
即使存在重复行记录也可以避免批量insert失败。
边栏推荐
- 无人艇轨迹跟踪的预设性能抗扰控制研究
- 微信视频号视频如何下载提取?视频号直播回放如何下载?方法很简单!
- WinForm枚举容器中的控件,实现控件统一事件处理机制
- 周鸿祎:微软抄袭了360安全模式 所以成为美国最大的安全公司
- What happened when the computer crashed?
- Flexible distribution parameters of mechanical system modeling and control of research and development
- 如何用Golang来手撸一个Blog - Milu.blog 开发总结
- 腰部外骨骼机器人线性自抗扰控制器参数优化
- MySQL查询性能优化
- Matlab基础(4)——矩阵
猜你喜欢
Difference between C# enumeration type and xaml
关于香港高防IP需要关注的几个问题
Verilog grammar basics HDL Bits training 08
Apifox generates interface documentation tutorial and operation steps
崩了,该来的终究躲不掉
电脑奔溃的时候,到底发生了什么?
微信视频号视频如何下载提取?视频号直播回放如何下载?方法很简单!
PyQt5快速开发与实战 8.2 绘图 && 8.3 QSS的UI美化
即时通讯-改变社交与工作状态的新型软件
解码Redis最易被忽视的CPU和内存占用高问题
随机推荐
The method of judging the same variable without the if branch
A tutorial on how to build a php environment under win
关于香港高防IP需要关注的几个问题
嵌入式环境下并发控制与线程安全
历时两月,终拿字节跳动offer,算法面试题分享「带答案」
Underwater target detection method based on spatial feature selection
概率论的学习整理1: 集合和事件
概率论的学习整理--番外1:可重复且无次序的计数公式C(n+k-1,k) 的例题 : 同时丢3个骰子,会有多少种情况?答案不是216而是56!
Rust from entry to proficient 02-installation
北上广线下活动丨年底最不可错过的技术聚会都齐了
nodeJs--fs模块
EXCEL解决问题:如何查找目标区域,是否包含指定字符串?
IO/multiplexing (select/poll/epoll)
数据湖(十八):Flink与Iceberg整合SQL API操作
I built another wheel: GrpcGateway
基于空洞补全的动态SLAM方法
saltstack学习2grains&pillar
数字量输入输出模块DAM-5088
Verilog grammar basics HDL Bits training 07
Apifox generates interface documentation tutorial and operation steps