鍍金池/ 問答/Java  數(shù)據(jù)庫/ insert為什么會報死鎖

insert為什么會報死鎖

數(shù)據(jù)庫:mysql 引擎:innodb
錯誤如下:

### Error updating database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
### The error may involve t8t.prs.ctm.verification.mapper.VerifyOrderMapper.insertSelective-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO ctm_verify_order  ( id,code,schedule_node_id,project_id,verify_status,satate_id,city_id,town_id,house_valuation_area,contract_price,house_style,create_user,create_time,update_user,update_time ) VALUES( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
; SQL []; Deadlock found when trying to get lock; try restarting transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:263)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447)
    at com.sun.proxy.$Proxy45.insert(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:52)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
    at com.sun.proxy.$Proxy50.insertSelective(Unknown Source)

該插入在事務(wù)過程中,前面有一次對歷史記錄的更新,后面會對新插入的記錄更新

回答
編輯回答
離殤

用show engine innodb status看一下LATEST DETECTED DEADLOCK日志是不是更新和插入造成的死鎖,修改一下sql的寫法。

2018年9月2日 01:41