Hi,
I have two POJOs and OneToOne relationship between them.
@Entity
public class Person {
private Address address;
@OneToOne
@JoinColumns({
@JoinColumn(name="I_ADDRESS_HOMEADDRESS", referencedColumnName="I"),
@JoinColumn(name="C_ADDRESS_HOMEADDRESS", referencedColumnName="C")})
public Address getHomeAddress() {
return this.address;
}
public void setHomeAddress(Address address) {
this.address = address;
}
}
@Entity
public class Address {
private Person person;
@OneToOne(mappedBy="homeAddress")
public Person getPerson() {
return person;
}
public void setPerson(Person person) {
this.person = person;
}
}
I can create a relationship from Person to Address.
However, when I delete an Address object which has a relationship to Person, the foreign key in Person which points to Address does not get updated.
This means when the Address is deleted, the Person has an invalid reference to it.
I thought hibernate behind the scenes, would update the foreign key back to null.
Any ideas? Are my doing something wrong?
|