获取org.apache.openjpa.persistence.OptimisticLockException:无法获取“null”上的对象锁

时间:2018-05-16 04:23:40

标签: java jpa db2 websphere optimistic-locking

我在执行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

1 个答案:

答案 0 :(得分:0)

带有SQLERRMC = 00C90088的

sqlode -913表示您的连接遇到了DEADLOCK。

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

网上有很多热门提供有关如何降低Db2死锁可能性的建议,您的研究也是如此。

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

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

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

相关问题