java - 类型 "class *"未被增强的JPA异常

标签 java jpa openjpa

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

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

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.

然而,this article说我的类应该在运行时得到增强。 ChangeRoutineConsumedPK 是一个可嵌入类。有人可以看看我的课并告诉我我做错了什么吗?谢谢。

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:

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

最佳答案

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

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

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

关于java - 类型 "class *"未被增强的JPA异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19042416/

相关文章:

java - 多维数组 : Java. 这段代码是如何工作的?

java - 如何使用 Google App Engine 调试服务器测试接收带附件的电子邮件

java - eclipselink (JPA) 异常 : composite primary key @JoinColumn

Hibernate:是否可以在二级缓存中保存 transient 字段?

java - JPA、自定义查询和日期

java - Websphere 7 + EJB3 中的内存泄漏,大量 ClassMapping 实例

java - hadoop - HDFS 文件分发

Java编译, "No such file or Directory"

warnings - openjpa现有列不兼容

java - JPA:@ManyToOne 关系的默认列名映射