EntityClass has no primary key specified (InheritenceType.JOINED)

Hallo, ich habe folgendes Problem:

Ich habe 2 Klassen “Oberklasse” und “Unterklasse”:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Oberklasse implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
//...
}
@Entity
public class Unterklasse extends Oberklasse implements Serializable {
    private static final long serialVersionUID = 1L;
//...
}

Unterklasse benötigt meiner Meinung nach keinen eigenen PrimaryKey, da dieser ja von Oberklasse geerbt wird. Jetzt meckert aber mein Glassfish 3.1.2.2 folgendes:

Exception Description: Predeployment of PersistenceUnit [FundraisingManagerPU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class Unterklasse] 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.
org.glassfish.deployment.common.DeploymentException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [FundraisingManagerPU] failed.
Internal Exception: Exception [EclipseLink-7161] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class Unterklasse] 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.

Ich hoffe, mir kann da jemand helfen…stehe irgendwie voll auf dem Schlauch…

Bei InheritanceType.JOINED brauchst du IMHO eine ID, weil eine andere Tabelle pro SubClass verwendet wird.

Hi,

versuch es mit der @MappedSuperClass Annotation:

public abstract class AbstractIdVO implements IPSValueObject {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "id")
	private String id = UUID.randomUUID().toString();

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String toString() {
		return "AbstractIdVO [id=" + id + "]";
	}

}

Bei jeder Subclass dann: (Hinweis: Bei mir ist noch eine Klassenhierarchie dazwischen "AbstractTrackingVO, dass jedoch genau wie „AbstractIdVO“ annotiert ist.

@Table(name = "users", uniqueConstraints = { @UniqueConstraint(columnNames = { "username" }) })
public class UserVO extends AbstractTrackingVO {

	private static final long serialVersionUID = 1L;

	@Column(name = "password")
	private String password = null;

	@Column(name = "username")
	private String username = null;
}```

Gruß,

Martin

Danke Martin, damit hat es funktioniert :slight_smile: