-->
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.  [ 4 posts ] 
Author Message
 Post subject: Setting null with cascade="delete-orphan"?
PostPosted: Mon Nov 05, 2007 4:22 am 
Newbie

Joined: Mon Nov 05, 2007 4:05 am
Posts: 4
I have a simple Parent/Child relationship defined as:
Code:
<class name="Parent" table="parent">
  ...
  <set name="children" cascade="delete-orphan">
    <key column="parentId" />
      <one-to-many class="Child" />
   </set>
</class>

<class name="Child" table="child">
  ...
  <property name="parentId" />
</class>

Now when I call parent.getChildren().remove(child) Hibernate first preforms a SQL update of parentId = null on the child row being removed, then it performs the delete. However, in normal operations the parentId column is set to "NOT NULL" so this triggers a constraint error. Is there a way to turn this behavior off so that the child is simply deleted without the initial null update? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 10:02 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
hi byronvf,

Use not null =true for key column.Another way is use Bydirectional mapping .That might help

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 05, 2007 8:52 pm 
Newbie

Joined: Mon Nov 05, 2007 4:05 am
Posts: 4
Thanks for the reponse, I also found this in the documentation which addresses my question:

http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#example-parentchild

It's consistent with your advice. I needed to also add the inverse="true" attribute to prevent inserting a null value when adding a child to the collection. It seems to be working now, even though I wish I could say I firmly understand what's going on underneath the hood. More study seems in order...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 06, 2007 12:38 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi byronvf,

If My advice some where helps you then Plz.. give credit to it.

_________________
Dharmendra Pandey


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