I have an entity class which inherits from four level of inheritance in which the top level parent defines the primary key (@Id) and I'm having trouble figuring out what I did wrong as I get this error:
Entity class [class D] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass. If you have defined PK using any of these annotations then make sure that you do not have mixed access-type (both fields and properties annotated) in your entity class hierarchy.
Here's the hierarchy:
A->B->C->(Entity)D
This is my non-entity class that gives the values to its children:
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@MappedSuperclass
public class A implements Serializable {
@Id
@GeneratedValue
protected Long id;
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
protected Date deleted;
public Date getDeleted() {
return deleted;
}
public void setDeleted(Date deleted) {
this.deleted = deleted;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
and this is one of its child :
@MappedSuperclass
public abstract class B extends A implements Serializable {
}
B->C
import javax.persistence.Entity;
import javax.persistence.Transient;
@MappedSuperclass
public class C extends B{
protected String name;
protected String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
And finally C-> (Entity)D
@Entity
public class D extends C{
private String codeD;
public String getCodeD(){return codeD;}
public String setCodeD(String codeD) {this.codeD = codeD;}
}
According to every source I've found, normally with the @MappedSuperclass and implementing Serializable it should work. Thought I've tried implementing Serializable even every step of the hierarchy but I received the same error message.
I'm currently using Payara 4.1.1.1621. I don't know if that might be the problem as I've seen this kind of error in Payara on some thread but they all miraculously resolved themselves.