I am using Hibernate and I have these two classes.
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, ...)
//should I use appl.persist() or applYear.persist() so that both sides will be persisted //at once?
}
As said for example in API, operations are cascaded to the associated entities. In your case this means that calling
will cascade persist operation also to the elements of
applicantYearslist. Functionality is similar for refresh operation.