尝试将实例强制转换为PersistenceCapable失败.确保它已得到增强

编程入门 行业动态 更新时间:2024-10-07 12:23:29
本文介绍了尝试将实例强制转换为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:

2.5.省略OpenJPA增强器

2.5. Omitting the OpenJPA enhancer

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

OpenJPA does not require that the enhancer be run. If you do not run the enhancer, OpenJPA will fall back to one of several possible alternatives for state tracking, depending on the execution environment.

Java 6类重新转换:

Java 6 class retransformation:

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

if you are running your application in a Java 6 environment, OpenJPA will attempt to dynamically register a ClassTransformer that will redefine your persistent classes on the fly to track access to persistent data. Additionally, OpenJPA will create a subclass for each of your persistent classes. When you execute a query or traverse a relation, OpenJPA will return an instance of the subclass. This means that the instanceof operator will work as expected, but o.getClass() will return the subclass instead of the class that you wrote. You do not need to do anything at all to get this behavior. OpenJPA will automatically detect whether or not the execution environment is capable of 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失败.确保它已得到增强

本文发布于:2023-11-26 21:50:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635331.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   实例   PersistenceCapable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!