java - Spring Boot jpa - 与同一实体的 OneToMany 多重关系
问题描述
这是多字段关系的示例,但我想要一个具有多对一的实体关系,如下面的场景。
我想设计一个像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
那么如何配置关系?
我对具有单一实体关系的 ManyToOne 或 OneToMany( Example1 , example2 ) 有一个想法
解决方案
推荐阅读
- android-studio - 如何在 Android Studio 或 Visual Studio Code 中找到未使用的颤振类
- java - Maven 依赖项为每个依赖项提供 ValidatorException 警告
- node.js - 从 postgresql 数据库列中删除空格不起作用
- apache-kafka - kafka 连接转换订购保证
- python - 如何在 AWS Lambda 上执行 Python REST API 测试套件
- neural-network - 在 PyTorch 中提取图像的编码表示?
- web-crawler - 从 Apache Nutch 清除数据
- asp.net - Visual Basic 编译器 (vbc.exe) 用完所有系统内存(RAM 和虚拟)
- excel - 如何将日期时间存储到 VBA 中的变量以保存在 Excel 数据库中
- angular - Summernote 在 Angular 8 中无法正确更改内容