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

问题描述 投票:0回答:4

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

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

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

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

改变日常消耗:

@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){...}
}

改变日常消费PK:

@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) {...}
}
java jpa openjpa
4个回答
3
投票

ChangeRoutineConsumedPK 类未添加到 persistence.xml 中,并且我已关闭自动类扫描。

将类添加到 persistence.xml 解决了问题

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

0
投票

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

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


0
投票

与上面的答案类似,在 MacOS 上的 Intellij 中,我将以下内容添加到 JUnit 运行参数中:

-javaagent:/Users/YOUR_USERNAME/.ivy2/cache/org.apache.openjpa/openjpa/bundles/openjpa-3.1.1.jar

这解决了我的问题。


0
投票

我在 Idea 中遇到错误,并且 mvn clean install -DskipTest -U 有效。

© www.soinside.com 2019 - 2024. All rights reserved.