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
|