根据以下代码,我有 2 个实体具有一对一的关系。
@Entity
public class Student
{
@Id
@GeneratedValue
private long id;
private String name;
@OneToOne( fetch = FetchType.LAZY )
private Passport passport;
}
@Entity
public class Passport
{
@Id
@GeneratedValue
private long id;
private String number;
@OneToOne( fetch = FetchType.LAZY, mappedBy = "passport" )
private Student student;
}
我是否需要创建两个 spring Data Repositories 来存储 Passport 和 Student ?
还是有更好的解决方案?