错误信息如下:

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. Ado.NET SQLHelper(2)

    测试发现前面发的那个功能太简单,不能调用getdate()等内部函数.  完善后重载了insert和update两个功能,将函数作为字符串传入SQL语句构造,需要的可以试用一下   using Sys ...

  2. 抓包工具fiddler的Https证书设置

    一.工具(option)--设置(setting)-- https-- 动作(actions)-- (open windows certificate manger)-- 搜索(fiddler)删除所 ...

  3. DevOps - 实施原则

    章节 DevOps – 为什么 DevOps – 与传统方式区别 DevOps – 优势 DevOps – 不适用 DevOps – 生命周期 DevOps – 与敏捷方法区别 DevOps – 实施 ...

  4. Vulkan 之 Layers

    Layers 暴露给api层,不像传统图形API集成在驱动里面,开发者根据自己的需要进行开启,最终目的还是为了提高性能. The Loader he loader is the central arb ...

  5. 12.Python的高级语法和用法

    # from enum import Enum # 枚举 # class VIP(Enum): # YELLOW = # YELLOW_ALIAS = # 别名 # GREEN = # BLACK = ...

  6. servlet中urlpatterns注意事项

    在servlet中, @WebServlet(urlPatterns="/newsAdd")接收 resp.sendRedirect("/wedding/houtai/N ...

  7. 020-PHP浏览目录

    <?php // 使用表格浏览目录的结构 print("<TABLE BORDER= '1'>"); // 创建表格的头 print("<TR&g ...

  8. PhotoView 实现与图片进行简单的交互

    本文的category是根据VIPhotoView来做参考,在此基础上添加个加载网络图片. 此category主要功能是与图片进行交互,双击放大图片,捏合等操作. 感谢vitoziv ! VIPhot ...

  9. XTU 1205 Range

    还是五月湘潭赛的题目,当时就是因为我坑...连个银牌都没拿到,擦. 这个题目枚举区间是不可能的,明显是要考虑每个数对全局的影响,即找到每个数最左和最右能满足是最大的位置 以及 最小的时候,相乘即为该数 ...

  10. gdb 常用选项

    gdb 常用选项 help:查看命令帮助,具体命令查询在gdb中输入help + 命令,简写h run:重新开始运行文件(run-text:加载文本文件,run-bin:加载二进制文件),简写r st ...