Tables : Student, Address Student.ADDR_ID column maps to Address.ID
Annotation in my Student class is as follows
public class Student {
String name, surname;
int rollNumber;
Teacher classTeacher;
Address address;
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="ADDR_ID")
public Address getAddress() {
return address;
}
:
:
It is working fine in create and update case.
If I change the address of Student to a new then it creates a new row but does not delete the row for old address. If I set address to null still it does not delete
e.g.
Student s1 = session.get(Student.class, 24);
Address addr = new Address();
session.save(addr);
s1.setAddress(addr);
session.save(s1);
or
Student s1 = session.get(Student.class, 24);
s1.setAddress(null);
I have set cascade ALL. What extra/different needs to be done. Is Inverse applicable here ?
You should use
orphanremoval = true
if that suffice for you