This is example for multiple field relationship
但我想要一个多实体的实体关系,有很多人,就像下面的场景。
我想设计一个像stackoverflow这样的网站。
所以现在我发现了3个实体
-
问题
-
回答
-
评论
我把每个实体设计成
评论
public class Comment {
private int commentId;
private String content;
}
回答
public class Answer {
private int answerId;
private String content;
@OneToMany
private List<Comment> comments;
}
问题
public class Question {
private int questionId;
private String content;
@OneToMany
private List<Comment> comments;
@OneToMany
private List<Answer> answers;
}
在这里
Comment
两者均指实体
Answer
和
Question
那么如何配置关系呢?
我和一个男人或一个女人有个主意(
Example1
,
example2
)具有单一实体关系