使用@Embeddable注解,组合键的类必须实现 Serializable 接口
@Data@Embeddablepublic class UserCommentId implements Serializable { ???@OneToOne ???@JoinColumn(name = "user_id") ???private User user; ???@OneToOne ???@JoinColumn(name = "comment_id") ???private Comment comment;}
使用:
@Data@Entitypublic class UserComment { ???@EmbeddedId ???private UserCommentId userCommentId;}
Hibernate 组合主键的使用
原文地址:https://www.cnblogs.com/cearnach/p/9255429.html