答案 0 :(得分:0)
这是用户和他的个人资料之间的OneToOne映射
@Entity
public class User {
@Id
private int id;
private String name;
@OneToOne(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
private Profile profile;
}
个人资料实体
@Entity
public class Profil{
@GenericGenerator(name = "generator", strategy = "foreign",
parameters = @Parameter(name = "property", value = "user"))
@Id
@GeneratedValue(generator = "generator")
private int id;
@OneToOne(fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
private User user;
}