JPA 派生标识符的两种实现方式
阅读原文时间:2023年07月15日阅读:2

方法一:
@Entity
@IdClass(ModuleId.class)
public class Module {

@Id  
private Integer index;

@Id  
@ManyToOne  
private Page page;

private Integer cols;  

}

方法二:

@Entity
public class Element {

@EmbeddedId  
private ElementId id;

@ManyToOne  
@MapsId("pageId")  
@JoinColumn(name = "mypage\_id")  
private Page page;

private String name;  

}