我在尝试使用 jpa.AM 持久化对象时遇到以下错误
NestedThrowables:
<openjpa-1.2.2-SNAPSHOT-r422266:778978M-OPENJPA-975 nonfatal store error> org.apache.openjpa.persistence.OptimisticLockException: An optimistic lock violation was detected when flushing object instance "org.apache.openjpa.enhance.com$ibm$cloud$bss$client$db$data$Offeringattribute$pcsubclass-com.ibm.cloud.bss.client.db.data.Offeringattribute-10013800" to the data store. This indicates that the object was concurrently modified in another transaction.
现在我上次通过插入一些刷新语句解决了这个错误,如下所示
em.persist(xyz);
em.flush(); //added this line
dbAttr.setOid((xyz.getId());
em.merge((xyz);
但是我不记得上次我是否做了其他事情。即使在添加此刷新语句后我仍然收到此错误。
注意:我正在将我的应用程序作为独立控制台应用程序运行,并且确信只有 1 个线程正在运行
最佳答案
您正在启用子类化的情况下运行,并且存在许多已知问题。首先,首先阅读本页有关 enhancing your entities 的内容。 。整个过程不会超过几分钟,从长远来看,您会成为一个更快乐的露营者。该链接的目的是您需要设置以下属性并使用另一种增强方法。
<openjpa.RuntimeUnenhancedClasses=unsupported/>
如果这不能让您继续下去,您需要发布您的实体以获取有关正在发生的情况的更多线索。
-瑞克
关于java - 使用jpa更新对象时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743170/