com.ibm.db2.jcc.am.SqlTransactionRollbackException:DB2 SQL错误:SQLCODE = -911,SQLSTATE = 40001,SQLERRMC = 68,DRIVER = 3.65.110

时间:2018-05-08 08:52:46

标签: java hibernate db2 locking deadlock

知道这有很多问题。这是因为数据行是由其他线程更新的,而另一个线程无法获取锁。 但是,我想详细询问:

我有一些代码如下:

// catch all for hibernate super exception
    public SystemErrorCode map(final org.hibernate.JDBCException dae) {
        log.info( "dae : " + dae );
        log.info( "dae error code : " + dae.getErrorCode( ) );
        log.info( "dae sql : " + dae.getSQL( ) );
        log.info( "dae sql exception : " + dae.getSQLException( ) );
        log.info( "dae sql state : " + dae.getSQLState( ) );
        log.info( "dae cause : " + dae.getCause( ) );
        log.info( "dae message : " + dae.getMessage( ) );
        return new SystemErrorCode( "DAO0005", SYSTEM_DAO );
    }

这是日志:

dae : org.hibernate.exception.LockAcquisitionException: could not execute native bulk manipulation query
dae error code : -911
dae sql : update PHistory SET  currentStatus = :currentStatus , MODIFIEDDATETIME = CURRENT TIMESTAMP where pHistoryId = :pHistoryId 
dae sql exception : com.ibm.db2.jcc.am.SqlTransactionRollbackException: DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68, DRIVER=3.65.110
dae sql state : 40001
dae cause : com.ibm.db2.jcc.am.SqlTransactionRollbackException: DB2 SQL Error: SQLCODE=-911, SQLSTATE=40001, SQLERRMC=68, DRIVER=3.65.110
dae message : could not execute native bulk manipulation query

当我查看代码时,实际上没有其他线程可以更新同一条记录,因为pHistory是主要的并且是唯一的。

然而,我一直在制作这个东西,我不能在我的本地或SIT或UAT模拟它。我试图知道什么线程,或者我的代码在哪里,我实际上锁定了同一行,然后导致此错误。

1 个答案:

答案 0 :(得分:0)

I finally found the root cause and manage to solve it. Its actually cause by the huge number of PHistory table records, and many linkage with other table, and less of indexing.

I run a db2expln on this query and found that add the suggested index will improve 99% of the performance. After I add the index, and monitoring for few months, and good news that is no more this exception happen in my program.

So, its actually not cause by other thread updating the same row, I am finding the solution in wrong way. Until I check the index. Thus, in future, if there is some similar issue happen to you, how about put a try for index and see the result.