-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Referential integrity
PostPosted: Mon Feb 26, 2007 1:17 pm 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
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?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 27, 2007 7:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no because this isde is mappedBy, which means the association is not taken care of from this side

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 6:08 am 
Senior
Senior

Joined: Mon Jul 24, 2006 8:43 am
Posts: 160
Well explained, makes sense thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.