javajpaopenjpa

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


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

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.

However, this article says 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.

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

Solution

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

    Adding the class to the persistence.xml fixed the problem

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