When saving a bi-directional @OneToOne mapping, is hibernate supposed to make a record on both tables?
I have a table interview
with column applicant_id
that references applicant
table with field interview_id
and vice versa, the columns being the FKs.
When creating a column by executing session.save(theInterview)
is hibernate supposed to create a record in applicant
table applicant_id
? Do I need to update the existing record myself or am I doing things wrong?
Edit
Just was working on my JSP file and noticed that I could see that the reference exists on the applicant too. But the query on the DB shows the field empty?
Hibernate Mapping
@OneToOne(mappedBy="applicant_id", cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "interview_id")
private Interview interview_id;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "applicant_id", nullable=false)
private Applicant applicant_id;
Interview_id
column on anapplicant
after recording an interview instance.
Can you provide your Hibernate mapping? What your asking about is Cascade, i.e. should Hibernate cascade save of the Applicant. That depends entirely on whether Hibernate has been instructed to cascade save on the relationship.