-->
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: Cascading a OneToOne relation when updating
PostPosted: Wed Jan 16, 2008 2:33 am 
Newbie

Joined: Wed Jan 16, 2008 2:22 am
Posts: 4
I made a simple example to explain my problem.

Code:
Public class Person {

@Entity
private Address address;

@OneToOne
@Cascade(CascadeType.ALL)
@JoinColumn(name="ADDRESS_ID")
public Address getAddress() {...}
public void setAddress(Address address);

}



I made a unidirectional OneToOne mapping from Person to Address, and my cascading works when I delete Person, Address is also deleted.

But now when I execute the following code :
Code:
person.setAddress(new Address);
personDao.update(person);


when i look in the database the address_id of the person is correctly changed and references to the new address.
The problem is that the old address is still in the database, no longer in use by anything.

What is the best way to solve this, I don't want any unreferenced address records in my database.
Shoud I create a collection of addresses in my person Entity, and only put one address in it ?

Thanks in advance for any help provided


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 2:05 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
would this annotation work?

@Cascade(DELETE_ORPHAN)

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 2:01 am 
Newbie

Joined: Wed Jan 16, 2008 2:22 am
Posts: 4
DELETE_ORPHAN can only be used for collection, but I also looked on the forum and found this : http://forum.hibernate.org/viewtopic.php?p=2287278 so DELETE_ORPHAN is not going to help me out


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.