本文介绍了尝试将实例强制转换为PersistenceCapable失败.确保它已得到增强的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试使用OpenJPA 2.0.1,并且得到:

I'm trying out OpenJPA 2.0.1 for the first time, and am getting:

79  WARN   [main] openjpa.Runtime - The configuration property named "openjpa.Id" was not recognized and will be ignored, although the name closely matches a valid property called "openjpa.Id".
179  INFO   [main] openjpa.Runtime - Starting OpenJPA 2.0.1
371  INFO   [main] openjpa.jdbc.JDBC - Using dictionary class "org.apache.openjpa.jdbc.sql.PostgresDictionary" (PostgreSQL 8.4.4 ,PostgreSQL Native Driver PostgreSQL 9.0 JDBC4 (build 801)).
<openjpa-2.0.1-r422266:989424 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Attempt to cast instance "x.quality.QualityQuery@4c4b11e9" to PersistenceCapable failed.  Ensure that it has been enhanced.
FailedObject: x.quality.QualityQuery@4c4b11e9
    at org.apache.openjpa.kernel.BrokerImpl.assertPersistenceCapable(BrokerImpl.java:4559)
    at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2561)
    at org.apache.openjpa.kernel.BrokerImpl.persist(BrokerImpl.java:2423)
    at org.apache.openjpa.kernel.DelegatingBroker.persist(DelegatingBroker.java:1069)
    at org.apache.openjpa.persistence.EntityManagerImpl.persist(EntityManagerImpl.java:706)
    at ...

根据 OpenJPA文档,我不需要做任何事情就能在运行时获得基本增强:

According to the OpenJPA docs, I shouldn't have to do anything to get the basic enhancement at runtime:

OpenJPA不需要增强子可以运行.如果不运行增强器,OpenJPA将退回到几种可能的选择之一用于状态跟踪,具体取决于执行环境.

OpenJPA does not require that theenhancer be run. If you do not run theenhancer, OpenJPA will fall back toone of several possible alternativesfor state tracking, depending on theexecution environment.

Java 6类重新转换:

Java 6 classretransformation:

如果您正在跑步Java 6中的应用程序环境中,OpenJPA将尝试动态注册将重新定义的ClassTransformer您的持久班级跟踪对持久数据的访问.此外,OpenJPA将创建一个每个持久性的子类类.当您执行查询或遍历一个关系,OpenJPA将返回子类的实例.这意味着操作员将按预期工作,但是o.getClass()将返回子类而不是您编写的类.您根本不需要做任何事情得到这种行为.OpenJPA将自动检测是否执行环境是有能力的Java 6类重新转换的过程.

if you are runningyour application in a Java 6environment, OpenJPA will attempt todynamically register aClassTransformer that will redefineyour persistent classes on the fly totrack access to persistent data.Additionally, OpenJPA will create asubclass for each of your persistentclasses. When you execute a query ortraverse a relation, OpenJPA willreturn an instance of the subclass.This means that the instanceofoperator will work as expected, buto.getClass() will return the subclassinstead of the class that you wrote.You do not need to do anything at allto get this behavior. OpenJPA willautomatically detect whether or notthe execution environment is capableof Java 6 class retransformation.

有什么线索为什么这行不通?非常感谢...

Any clues why this isn't working? Thanks much...

(关于openjpa.Id警告发生的原因的奖励,我没有设置任何此类属性...)

(Bonus points for why the openjpa.Id warning happens - I haven't set any such property...)

推荐答案

啊哈,原来答案是通过的:

Aha, turns out that the answer was to pass in:

"openjpa.RuntimeUnenhancedClasses" => RuntimeUnenhancedClassesModes.SUPPORTED

到配置图.为什么不确定,为什么没有对此做更清楚的记录?

to the configuration map. Why this is not documented more clearly, I'm not sure...

这篇关于尝试将实例强制转换为PersistenceCapable失败.确保它已得到增强的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 03:36