-->
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.  [ 1 post ] 
Author Message
 Post subject: delete problem with foreign key constraints
PostPosted: Mon Jun 14, 2004 7:54 pm 
Senior
Senior

Joined: Sun Oct 26, 2003 5:05 am
Posts: 139
Hi, I'm trying to delete a row in hibernate that has a foreign constraint on it to delete other things. In most of my tables, I can just delete the row and the database management system itself will cascade and delete the rest of the dependant rows for me (as expected). However, I'm trying to delete a row from a table that has a foreign key constraint to another row in the same table (parent_id). However, when I go to delete the parent row, it leaves the children there (even though if I delete this row outside of my application and inside.

Now, this is sort of screwy because if I delete the parent row right out of the database, it will actually carry out the cascades no problem. Also, if I delete a record from another table that sets off a deletion of this parent row, the children will be deleted too, so it's just when - and only when - I delete the parent row in my application directly. It's as if hibernate refuses to let postgres do it's thing.

The weird thing is, it does delete the parent row but all the children are still there with parent_id = null. Now, that's just weird. I did some sql debug statements and nothing shows up during the deletion either, so I figure hibernate is inserting them again or something but I'm sort of at a loss.

I guess I could try cascade="delete-orphan", but I wanted to strive for simplicity and consistency. If all of my objects are being deleted via foreign key constraints inside my dbms, I shouldn't have to tell hibernate to clean up - or in order words, clean up something that hibernate is doing wrong.

I'm sure it's just a mapping problem and I'm sure you guys have seen this problem before, so I'm curious what do I need to put in my mapping file under my collection to make this behaviour stop?

Thank you very much for your help in this issue,
Ken


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

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.