【问题标题】:Getting org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null"获取 org.apache.openjpa.persistence.OptimisticLockException:无法在“null”上获得对象锁
【发布时间】:2018-05-16 04:23:39
【问题描述】:

我在执行 EntityManager.find() 时遇到异常。我们正在为我们的应用程序使用 DB2 数据库和 WAS 8.0 服务器。非常感谢任何帮助。

Caused by: <openjpa-2.1.2-SNAPSHOT-r422266:1709309 nonfatal store error> org.apache.openjpa.persistence.OptimisticLockException: Unable to obtain an object lock on "null".
at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4930)
at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4908)
at org.apache.openjpa.jdbc.sql.DB2Dictionary.newStoreException(DB2Dictionary.java:603)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
at org.apache.openjpa.jdbc.kernel.PreparedSQLStoreQuery$PreparedSQLExecutor.executeQuery(PreparedSQLStoreQuery.java:139)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1012)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:870)
at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:801)
at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:315)
at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:331)

... 116 more

Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: DB2 SQL Error: SQLCODE=-913, SQLSTATE=57033, SQLERRMC=00C90088;00000304;ODNC001 .SNCPC145.X'200D65' '.X'43', DRIVER=4.15.134 {prepstmnt -1803801027 
SELECT a.column1 
FROM table_test a 
WHERE (a.column2 = ? AND a.column3 = ?) 
[params=(String) 00000, (String) 000011]} [code=-913, state=57033]
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:281)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:265)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:72)
at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:1183)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:284)
at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1787)
at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:274)
at org.apache.openjpa.jdbc.kernel.PreparedSQLStoreQuery$PreparedSQLExecutor.executeQuery(PreparedSQLStoreQuery.java:118)
... 123 more

【问题讨论】:

    标签: java jpa db2 websphere optimistic-locking


    【解决方案1】:

    带有 SQLERRMC=00C90088 的 sqlode -913 表示您的连接遇到了死锁。

    如果您的 Db2 服务器在 Z/OS 上运行,请向您的 DBA 寻求帮助以查找在两个事务中运行的其他 Db2 连接和 SQL 语句。两个连接使用的访问计划和隔离级别是也相关,任何适用的锁定超时也是如此。 Db2-server DBA 可以使用诊断工具来帮助您。

    网上有很多关于如何减少 Db2 死锁可能性的建议,因此请进行研究。

    您将需要知道 Websphere 连接(或包或 SQL 语句)使用的隔离级别,以及您的连接的 Db2 事务中的所有语句。

    消息中的其他标记也是相关的,即 ODNC001.SNCPC145 可能是涉及的表。

    Websphere 使用的 jdbc type4 驱动程序版本已过时(看起来像是来自 Db2 v10.1 fixpack 5 build),因此请考虑将其升级到当前版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多