错误信息如下:

2017-09-27 16:27:16.153 - 【com.ldyun.base.service.impl.BaseRetailOrderServiceImpl】 - 新增零售商品订单~org.springframework.dao.CannotAcquireLockException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
### The error may involve com.ldyun.retail.mapper.RetailGoodsMapper.updateBySql-Inline
### The error occurred while setting parameters
### SQL: update retail_goods SET stocks = stocks - CASE id WHEN 83 THEN 1 END,saleCount = saleCount + CASE id WHEN 83 THEN 1 END WHERE id IN (83)
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction
; SQL []; Lock wait timeout exceeded; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Lock wait timeout exceeded; try restarting transaction~

经过网上资料查询,原因为:Spring 事务嵌套造成死锁。

经核实代码的确是service里面调用service,且两个service都配置了事务。顶层service名称为addRetailOrder,内层service名称为updateBysql。

事务配置为:

	<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="add*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
<tx:method name="del*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
<tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
<tx:method name="insert*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />
<tx:method name="try*" propagation="REQUIRED" read-only="false" rollback-for="com.wm.base.exception.TransactionRollbackException" />
</tx:attributes>
</tx:advice>

解决方法为:

1、内层service实现方法配置@Transactional(propagation=Propagation.SUPPORTS)

	@Override
@Transactional(propagation=Propagation.SUPPORTS)
public int updateBySql(String sql) {
// TODO Auto-generated method stub
return retailGoodsDao.updateBySql(sql);
}

2、外层service不配置事务,即修改方法名称。

org.springframework.dao.CannotAcquireLockException异常分析的更多相关文章

  1. org.springframework.dao.CannotAcquireLockException解决

    java.sql.SQLException: Lock wait timeout exceeded 该异常为一个service中调用了另一个service,两个service对同一表进行操作,造成事务 ...

  2. 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException

    Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...

  3. 增删改查 报异常org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readO

    可能是Spring配置文件 事务通知里面的方法  与实际方法不匹配 <tx:advice id="advice" transaction-manager="tran ...

  4. org.springframework.dao.InvalidDataAccessApiUsageException: The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null

    通过这个简单的案例,手把手教给你分析异常信息(适合初学者看) org.springframework.dao.InvalidDataAccessApiUsageException: The given ...

  5. org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [41] did not match expected type [java.lang.Integer (n/a)];

    题记:以前记录过一些自己遇到的BUG,这个行为,让我一看报错的提示信息就能定位到问题的所在,后来记得比较多了,好多是重复性的再加上比较忙就没有详细的记录了,今天的工作量比较小,就顺便记录一下,以便以后 ...

  6. org.springframework.dao.InvalidDataAccessApiUsageException:The given object has a null identifi的解决方案

    异常信息: org.springframework.dao.InvalidDataAccessApiUsageException: The given object has a null identi ...

  7. org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode

    [spring]:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowe ...

  8. OpenSessionInViewFilter与org.springframework.dao.InvalidDataAccessApiUsageException

    报错:org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in r ...

  9. org.springframework.dao.EmptyResultDataAccessException

    public Wcrash getWcrashInfo(int id) { String sql = "select plateform_id,android_version,app_ver ...

随机推荐

  1. CentOS 6.5(x86_32)下安装Oracle 10g R2

    一.硬件要求 1.内存 & swap Minimum: 1 GB of RAMRecommended: 2 GB of RAM or more 检查内存情况 # grep MemTotal / ...

  2. G - Traffic

    vin is observing the cars at a crossroads. He finds that there are n cars running in the east-west d ...

  3. (九)微信小程序---for指令

    对于数据是列表 wxml <view wx:for="{{dataList}}">{{index}}-{{item}}</view> 我们可以看到上面的代码 ...

  4. NO7 利用三剑客awk-grep-sed-head-tail等7种方法实践

    ·seq   sequence  #序列·sed   stream editor  #(三剑客老二)流编辑器.实现对文件的增删改替换查.        -n #取消默认输出.sed -n '20,30 ...

  5. P1037 在霍格沃茨找零钱

    转跳点:

  6. UVA - 10129 Play on Words(欧拉回路)

    题意:将n个单词排成一个序列,保证相邻单词相邻处字母相同. 分析:每个单词看做一条有向边,字母为点,并查集看图是否连通,因为是有向图,所以最多只能有两个点入度不等于出度,且这两个点一个入度比出度大1, ...

  7. redmine处理规范

         开发: 1.       研发人员负责更新到的状态共有三个:  “进行中”. ”已解决”. ”需要反馈”. 2.       在开始修复bug的时候,把状态更新为”进行中”,把title更新 ...

  8. 基于高德开放平台Map Lab的数据可视化

    在Map Lab上创建可视化项目,首先需要添加数据.添加数据有4种方式,分别是: 上传CSV文件添加数据 上传Excel文件添加数据 连接在线数据库添加数据 提供在线数据API添加数据 一.数据上传说 ...

  9. require(): open_basedir restriction in effect. File(/www/wwwroot/xcx/zerg/thinkphp/start.php) is not within the allowed path(s): (/www/wwwroot/xcx/zerg/public/:/tmp/:/proc/) in /www/wwwroot/xcx/zerg/p

    解决方法: 在如下文件增加一项(如图所示) 在如下文件增加一项(如图所示): #php文件采用fastcgi解析并设置参数    location ~ \.php {        try_files ...

  10. Ubuntu14.04 无法关机 SpamAssassin speech-dispatcher

    在ubuntu14.04上安装完一些包后,关闭计算机就会出现关于标题中的两个错误. 1.在软件中心卸载spamAssassin 2.运行命令: sudo update-rc.d -f speech-d ...