-->
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: One-to-one association using a primary key
PostPosted: Wed Jan 26, 2005 9:56 pm 
Newbie

Joined: Thu Jan 06, 2005 6:27 pm
Posts: 10
In the one-to-one association using a primary key association example on page 223 of "Hibernate In Action", the one between user and address, how do I get the address to be deleted?

Let's say I create a user, give it an address and call save. Hibernate inserts the user into the user table and the address into the address table. Now, let's say the user becomes homeless. How do I get the address to be deleted? If I do user.setAddress(null), Hibernate does nothing. How do I get Hibernate to recognize that the other-end of the association, the address, is gone and must be deleted?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 4:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
session.delete() or enable cascading.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 27, 2005 3:47 pm 
Newbie

Joined: Thu Jan 06, 2005 6:27 pm
Posts: 10
I have enabled cascading. I have cascade="all" in the mapping (the DTD does not like cascade="all-delete-orphan" for a one-to-one mapping).

Here's what I am doing:

...get session
User u = new User();
u.setUid(123);
Address a = new Address();
a.setUid(123); // not really needed
a.setUser(u);
u.setAddress(a);

session.save(u);
tx.commit(); // Hibernate inserts user and address

u.setAddress(null);

session.save(u);
tx.commit(); // Hibernate does nothing! I expect it to delete address.

Do I explicitly need to call session.delete(a) to delete the address? I should be able to use one-to-one associations as shown above and expect Hibernate to delete the other end of the association, shouldn't I?


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.