Spring 弹簧靴中的复合键和积垢存放器

Spring 弹簧靴中的复合键和积垢存放器,spring,spring-boot,Spring,Spring Boot,我拥有以下实体: @Entity public class Attendance implements Serializable{ private static final long serialVersionUID = 1L; @Id @ManyToOne private Student student; @Id @ManyToOne private Session session

我拥有以下实体:

@Entity
public class Attendance implements Serializable{

        private static final long serialVersionUID = 1L;
        @Id
        @ManyToOne
        private Student student;
        @Id
        @ManyToOne
        private Session session;
        ...
如您所见,主键由两个类组成,而Crudepository只接受一种类型作为主键(Crudepository),请问如何解决这个问题?
谢谢。

您需要一个复合密钥。你可以用不同的方法来做。 您可以使用
@EmbeddedId
@embeddedable
,也可以使用
@IdClass
(这里您的实体类中有多个@id)

另见:

为什么您希望在您的桌子上放两个PK?PK应该是唯一的,因为学生和会话之间有多对多的关系,有额外的字段,请检查此链接:我以对角线形式阅读了它,但没有看到任何具有2
@Id
的实体。我看到了有不同含义的
@MapsId
。顺便说一下,同一实体中不能有2个
@Id