尝试使用hibernate保存/更新对象时发生org.hibernate.exception.LockAcquisitionException

时间:2018-09-07 15:15:51

标签: mysql java hibernate

在我们的应用程序中,我们尝试使用hibernate保存/更新对象。这段代码运行良好,但断断续续地我们面临着

org.hibernate.exception.LockAcquisitionException。

堆栈跟踪如下。

org.hibernate.util.JDBCExceptionReporter  - Lock wait timeout exceeded; try restarting transaction
[2018-08-30 01:43:08,261] [Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36] [] [] [] [] [] ajp-bio-12409-exec-273  org.hibernate.event.def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.exception.LockAcquisitionException: Could not execute JDBC batch update
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:107)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:180)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:657)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)

在我们的挖掘中,我们发现对象的更新查询卡在等待锁定的事务中。 但是还有另一个带有行锁的活动事务阻止了更新查询。奇怪的是,该事务与一个处于休眠状态且未运行查询的MySQL线程相关联。

我无法弄清楚为什么该交易仍处于活动状态。

0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 422169356276272, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 10420556, ACTIVE 7416 sec
63 lock struct(s), heap size 8400, 3 row lock(s), undo log entries 3
MySQL thread id 18011, OS thread handle 140689540835072, query id 16557351 {DBip} {DBName}

睡眠的MySQL线程使用行锁进行活动事务的可能原因是什么?

0 个答案:

没有答案