Eclipselink JPA本机更新查询抛出死锁异常

时间:2014-12-29 05:55:21

标签: jpa eclipselink jta

我正在使用Eclipselink JPA和JTA容器杠杆事务并尝试执行以下代码

  public int loadTargetTables() throws Exception {
    String sNavtive = "INSERT INTO TRGT_TABLE SELECT * FROM SRC_TABLE";
  int results = this.em.createNativeQuery(sNavtive).executeUpdate();    
  return results;
}

并注意源表和tartget表在无od列和数据类型中都是相同的。

我正在接受以下问题

[EL Finer]: 2014-12-29 11:13:04.681--Connection(17529256)--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Begin batch statements
[EL Fine]: 2014-12-29 11:13:04.681--Connection(17529256)--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--INSERT INTO TRGT_TABLE select  * FROM SRC_TABLE 
[EL Finer]: 2014-12-29 11:13:04.681--Connection(17529256)--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--End Batch Statements
[EL Finest]: 2014-12-29 11:13:04.681--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--reconnecting to external connection pool
[EL Fine]: 2014-12-29 11:14:01.625--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--SELECT 1 FROM DUAL
[EL Warning]: 2014-12-29 11:14:01.641--Thread(Thread[[ACTIVE] ExecuteThread: '15' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.BatchUpdateException: error occurred during batching: ORA-02049: timeout : distributed transaction waiting for a lock

Error Code: 17081
    at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeJDK12BatchStatement(DatabaseAccessor.java:873)
    at org.eclipse.persistence.internal.databaseaccess.DynamicSQLBatchWritingMechanism.executeBatchedStatements(DynamicSQLBatchWritingMechanism.java:143)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.writesCompleted(DatabaseAccessor.java:1707)
    at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.commitTransaction(DatabaseAccessor.java:408)
    at org.eclipse.persistence.internal.sessions.AbstractSession.basicCommitTransaction(AbstractSession.java:567)
    at org.eclipse.persistence.sessions.server.ClientSession.basicCommitTransaction(ClientSession.java:131)
    at org.eclipse.persistence.internal.sessions.AbstractSession.commitTransaction(AbstractSession.java:762)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransaction(UnitOfWorkImpl.java:1574)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitTransaction(RepeatableWriteUnitOfWork.java:649)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitTransactionAfterWriteChanges(UnitOfWorkImpl.java:1589)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:354)
    at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
    at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
    at weblogic.transaction.internal.ServerSCInfo.doBeforeCompletion(Unknown Source)
    at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(Unknown Source)
    at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(Unknown Source)
    at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:1355)
    at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:2172)
    at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:300)
    at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:267)
    at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:331)
    at weblogic.ejb.container.internal.BaseLocalObject.__WL_postInvokeTxRetry(BaseLocalObject.java:202)
    at weblogic.ejb.container.internal.SessionLocalMethodInvoker.invoke(SessionLocalMethodInvoker.java:44)

1 个答案:

答案 0 :(得分:0)

如错误说明中所述:distributed transaction waiting for a lock 可能你有一些 EntityManager(em)或uncommited或unrolled back transactions 的其他实例正在使用 TRGT_TABLE SRC_TABLE 表,或者它们在由数据库中的会话使用