Hello,
I have a question about how to use the one to one annotation and ensure that children are deleted when the parent is updated.
Hibernate version:
hibernate-core 3.3.1.GA
hibernate-annotations 3.4.0.GA
hibernate-commons-annotations 3.1.0.GA
My test classes:
Code:
@Entity
public class Person {
@Id
private String id = UUID.randomUUID().toString();
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = Address.class)
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private Address address;
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
@Entity
public class Address {
@Id
private String id = UUID.randomUUID().toString();
}
Example usage:
Code:
Person person = new Person();
Address address = new Address();
person.setAddress(address);
session.save(person);
person.setAddress(null);
session.update(person);
When i check the db i find that there is still a row in the address table.
Any ideas what I can do to solve this?
Regards
Ben Short