-->
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.  [ 2 posts ] 
Author Message
 Post subject: session.delete(parent), foreign key violated
PostPosted: Wed Jul 07, 2004 3:09 pm 
Newbie

Joined: Thu Jun 24, 2004 8:22 am
Posts: 7
Hi,

I have a Parent class which has a one-to-many Set of Children defined in the hbm file. In the hbm file of the Child, there is NO many-to-one relationship, as I don't have the need for a bi-directional relationship.
In the (Oracle) database, the child table has a not-null foreign key to the parent table, along with a cascading delete constraint (when parent is deleted, all childs will also be deleted). Therefore, I don't need the "cascade" setting in the Hibernate files.

Now, if I try session.delete(Parent), Hibernate tries to update the foreign key field of all children records to null. Of course this fails due to the not-null constraint on the child table. Now, how can I (WITHOUT setting a bi-directional relationship) actually delete the parent record, without Hibernate attempting to do the previously mentioned update of the children records? Deletion of the parent record would suffice, as the cascading delete on the children record will make sure they disappear also...

Thanks

Kind regards
Johan


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 11, 2004 1:17 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Your object model doesn't reflect your relational schema: the not-null foreign key constraint means: "This row B always has to have a valid ID of a row A". Your class B doesn't have a reference to A.

You have to make it bidirectional. Hibernate can't magically fill in an A when you save a B.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.