我正在使用 Hibernate,我有这两个类。
public class ApplicantYear{
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "APPLICANT_ID")
private Applicant applicant;
.
.
.
}
public class Applicant {
@OneToMany(mappedBy = "applicant", fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.REFRESH})
private Set<ApplicantYear> applicantYears = new HashSet<ApplicantYear>();
.
.
.
}
Public void testPersistence(){
Applicant appl= new ....
ApplicantYear applYear= new(appl, ...)
//我应该使用 appl.persist() 还是 applYear.persist() 以便双方都被持久化//一次?
}