1. 程式人生 > >JPA 派生標識符的兩種實現方式

JPA 派生標識符的兩種實現方式

string column public tid man pri one embed page

方法一:
@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;
}

JPA 派生標識符的兩種實現方式