org.springframework.dao.CannotAcquireLockException異常分析
阿新 • • 發佈:2018-12-21
錯誤資訊如下:
-
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
-
### 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
-
### 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
該異常為一個service中呼叫了另一個service,兩個service對同一表進行操作,造成事務巢狀,從而死鎖。
解決辦法:在當前方法前加入@Transactional(propagation=Propagation.SUPPORTS)