1
我有以下实体(短版):休眠:NaturalId与继承
GroupOfStudents:
@Entity
@Table(name = "group_of_students")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class AGroupOfStudents extends AModel {
}
Centuria:
@Entity
@Table(name = "cohort")
@PrimaryKeyJoinColumn(name = "id")
public class Cohort extends AGroupOfStudents {
@Column(nullable = false)
// @NaturalId <- here is the problem
private int number;
}
人群:
@Entity
@Table(name = "centuria")
@PrimaryKeyJoinColumn(name = "id")
public class Centuria extends AGroupOfStudents {
@Column(nullable = false)
// @NaturalId <- here is the problem
private int cohort;
@Column(nullable = false)
// @NaturalId <- here is the problem
private char maniple;
}
所以我有一个CourseLecture与GroupOfStudents。有不同的GroupOfStudents像Centuria或Cohort。但我希望队列的数字字段是NaturalId。这将导致错误:
AnnotationException: @NaturalId only valid on root entity (or its @MappedSuperclasses)
,但我为什么可以使用@NaturalId只有根实体?我怎样才能解决这个问题,而不会破坏我的类继承?