Java 类型“class *”尚未增强 JPA 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19042416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 13:36:57  来源:igfitidea点击:

The type "class *" has not been enhanced JPA exception

javajpaopenjpa

提问by coderatchet

I am running WebSphere v8, and using JPA persistence in a Java EE 6 environment.

我正在运行 WebSphere v8,并在 Java EE 6 环境中使用 JPA 持久性。

When I attempt to run code that deals with a particular entity, I run into this exception:

当我尝试运行处理特定实体的代码时,我遇到了以下异常:

javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: See nested exception; nested exception is: org.apache.openjpa.persistence.ArgumentException: The type "class au.com.combined.domain.changeroutine.ChangeRoutineConsumedPK" has not been enhanced.

javax.ejb.EJBTransactionRolledbackException:嵌套异常为:javax.ejb.EJBTransactionRolledbackException:嵌套异常为:javax.ejb.EJBException:参见嵌套异常;嵌套异常是:org.apache.openjpa.persistence.ArgumentException:类型“class au.com.combined.domain.changeroutine.ChangeRoutineConsumedPK”尚未增强。

However, this articlesays that my classes should already be enhanced at runtime. ChangeRoutineConsumedPK is an Embeddable Class. Could someone take a look at my class and tell me what i'm doing wrong? thank you.

但是,这篇文章说我的类应该已经在运行时增强了。ChangeRoutineConsumedPK 是一个可嵌入的类。有人可以看看我的班级并告诉我我做错了什么吗?谢谢你。

ChangeRoutineConsumed:

ChangeRoutineConsumed:

@Entity
@Table(name = ChangeRoutineConsumed.TABLE_NAME)
public class ChangeRoutineConsumed extends BaseBusinessObject {

    public static final String TABLE_NAME = "COCHANGEROUTINECONSUMED";

    @EmbeddedId
    private ChangeRoutineConsumedPK id;

    protected ChangeRoutineConsumed() {
        super();
    }

    public ChangeRoutineConsumed(@Min(1) long changeRoutineId, @NotNull String consumedBy){
        this(new ChangeRoutineConsumedPK(changeRoutineId, consumedBy));
    }

    public ChangeRoutineConsumed(@NotNull ChangeRoutineConsumedPK id){
        super();
        setId(id);
    }
    ...
    public int hashCode(){...};
    public boolean equals(Object obj){...}
}

ChangeRoutineConsumedPK:

ChangeRoutineConsumedPK:

@Embeddable
public class ChangeRoutineConsumedPK {

    @Column
    private long changeRoutineId;
    @Column
    private String consumedBy;

    public ChangeRoutineConsumedPK(){}

    public ChangeRoutineConsumedPK(long changeRoutineId, String consumedBy) {
        setChangeRoutineId(changeRoutineId);
        setConsumedBy(consumedBy);
    }
    ...

    public int hashCode() {...}
    public boolean equals(Object obj) {...}
}

采纳答案by coderatchet

The ChangeRoutineConsumedPK class was not added to the persistence.xml and i had turned off automatic class scanning.

ChangeRoutineConsumedPK 类没有添加到persistence.xml 中,我关闭了自动类扫描。

Adding the class to the persistence.xml fixed the problem

将类添加到persistence.xml 修复了问题

<persistence-unit ...>
...
<class>au.com.combined.domain.changeroutine.ChangeRoutineConsumedPK</class>
...
</persistence-unit>

回答by Dheeraj Pure

if you are executing from main class pass below parameter in execution java -javaagent:/openjpa.jar com.xyz.Main

如果您从主类中执行,则在执行时传递以下参数 java -javaagent:/openjpa.jar com.xyz.Main

if using eclipse give above value in run Configuration > arguments > VM arguments.

如果使用 Eclipse,请在运行配置 > 参数 > VM 参数中给出以上值。