这是父类
@MappedSuperclass
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class APostCommon extends Actionable {
private static final long serialVersionUID = 1L;
@Column(name = "TITLE")
private String title;
@Lob
@Column(name="DESCRIPTION")
private String description;
//omitted others for purity
}
这是一个儿童班
@Entity
@Table(name="QUESTION")
public class Question extends APostCommon {
private static final long serialVersionUID = 1L;
@Transient
private List<Answer> answers;
@Column(name="FOLLOW_COUNT")
private Integer followerCount;
@Column(name="ANSWER_COUNT")
private Integer answerCount;
//omitted others for purity
}
Answer
仅通过包含questionId
字段与超类不同
@Entity
@Table(name="ANSWER")
public class Answer extends APostCommon{
private String questionId;
//omitted others for purity
}
哪种数据模型适合我。我应该使用InheritanceType.SINGLE_TABLE
or TABLE_PER_CLASS
。未来有数百万条记录时会发生什么。