解决org.springframework.dao.DeadlockLoserDataAccessException
添加链接池后批量添加更新出现了死锁
org.springframework.dao.DeadlockLoserDataAccessException:
### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
### The error may exist in file [E:\java\project\bim-service\target\classes\mapper\ApiPropertiesMapper.xml]
### The error may involve com.tydt.bim.dao.ApiPropertiesMapper.batchAddProperties-Inline
### The error occurred while setting parameters
### SQL: insert into api_properties (`guid`,`name`,`file_id`,`value`,`unit`) values (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) , (?,?,?,?,?) ON DUPLICATE KEY UPDATE `value`=values(`value`),`unit`=values(`unit`)
### Cause: com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
; Deadlock found when trying to get lock; try restarting transaction; nested exception is com.mysql.cj.jdbc.exceptions.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
INSERT ON DUPLICATE KEY在执行时,innodb引擎会先判断插入的行是否产生重复key错误
如果存在,在对该现有的行加上S(共享锁)锁,返回该行数据给mysql,然后mysql执行完duplicate后的update操作,然后对该记录加上X(排他锁),最后进行update写入
如果有两个事务并发的执行同样的语句,那么就会产生death lock
解决方法:
1、尽量不对存在多个组合唯一键的table上使用该语句
2、在有可能有并发事务执行的insert 的内容一样情况下不使用该语句
先用select查看是否存在,再决定是insert还是update,但是这样耗时比较多
解决org.springframework.dao.DeadlockLoserDataAccessException的更多相关文章
- Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Multiple representations of the same entity解决方法
1.错误信息 Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUs ...
- java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceE解决方法
笔者是使用spring4.0时,报的错误: 原因是没有引入spring-tx-4.0.0.RELEASE.jar包,將spring-tx-4.0.0.RELEASE.jar添加到build path中 ...
- org.springframework.dao.DataIntegrityViolationException:
数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...
- javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
- org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];
题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后 ...
- OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException
报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r ...
- org.springframework.dao.EmptyResultDataAccessException
public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...
- org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案
1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...
- org.springframework.dao.InvalidDataAccessApiUsageException报错
2018-01-09 18:12:29,980 [qtp1501019626-21] ERROR - 外部接口调用方法[TestController$$EnhancerBySpringCGLIB$$8 ...
随机推荐
- hdu4027-Can you answer these queries? -(线段树+剪枝)
题意:给n个数,m个操作,分两种操作,一种是将一段区间的每个数都开根号,另一种是查询区间和. 解题:显然对每个数开根号不能用lazy的区间更新.一个一个更新必然爆时间,对1开根号还是1,如果一段区间都 ...
- 「GXOI / GZOI2019」宝牌一大堆 (DP)
题意 LOJ传送门 题解 可以发现「七对子」 和 「国士无双」直接暴力就行了. 唯一的就是剩下的"3*4+2". 考试的时候写了个爆搜剪枝,开了O2有50pts.写的时候发现可以D ...
- Subband Decomposition
子带分解. 例如语音信号是宽带信号,根据奈奎斯特采样定理,采样率为16kHz的语音信号的有效带宽是8KHz,不论是对于降噪,aec,vad,波束形成亦或是logfbank特征提取,我们都期望更精细的处 ...
- 洛谷P2580 于是他错误的点名开始了 题解
qwq!为什么!木有非结构体非指针的题解怎么阔以!所以, 我来辽~咻咻咻~ 题面 来分析, 我们可以先建一棵树,来存储整个名单, 然后再判断 ; i <= n; i++) { root = ; ...
- A♂G&C012
A♂G&C012 A AtCoder Group Contest 从大到小sort后输出\(a_2+a_4+a_6+\ldots a_{2n}\) 好♂啊,只会背结论/kk B Splatte ...
- kkk
#!/usr/bin/env python3# coding=utf-8# Author: yannanxiu"""create_rsa_key() - 创建RSA密钥m ...
- bzoj4868 期末考试 题解
https://www.lydsy.com/JudgeOnline/problem.php?id=4868 显然我们只关注最后出分的学科. 刚开始想的是dp,然而不知道如何记录状态. 突然就想到了正解 ...
- [算法模板]倍增求LCA
倍增LCA \(fa[a][i]\)代表a的第\(2^{i}\)个祖先. 主体思路是枚举二进制位,让两个查询节点跳到同一高度然后再向上跳相同高度找LCA. int fa[N][21], dep[N]; ...
- 从工厂流水线小妹到Google上班程序媛,看完后,我跪服了!
阅读本文大概需要 10.2 分钟. 文作者:Ling Sun 原文链接:https://www.zhihu.com/question/68154951/answer/546265013 我家境很不好, ...
- jvm(三)指令重排 & 内存屏障 & 可见性 & volatile & happen before
参考文档: https://tech.meituan.com/java-memory-reordering.html http://0xffffff.org/2017/02/21/40-atomic- ...