spring - compound key and CrudRepository in Spring boot
问题描述
I have the following entity :
@Entity
public class Attendance implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@ManyToOne
private Student student;
@Id
@ManyToOne
private Session session;
...
as you can see, the primary key is composed of two classes, and the CrudRepository accepts only one type as primary key (CrudRepository), how can I solve the problem please? Thank you.
解决方案
您需要一个复合键。你可以用不同的方式做到这一点。你可以使用@EmbeddedId
and@Embeddable
或者你可以使用@IdClass
(这里你的实体类中有多个@id)
推荐阅读
- javascript - 在java脚本中使用settimeout函数的异步javascript
- android - 触摸时加粗的 ClickableSpan
- reactjs - 使用 Redux 的 React JS 不会更新触发动作的状态
- c - 用于 2 个联系人标识符的 USB 触摸屏 HID 描述符
- python - 从 Python 特征工具中的特征工程中排除当前行
- android - 如何显示包含 10 列以上的表格?
- c# - c#将数据保存到密码protexted .xls并打开它
- angular - 从另一个组件更新组件道具
- r - 我可以在使用 knitr 编织整个文档之前检查重复的标签吗?
- laravel - Laravel - 在刀片视图中使用模型的静态功能