-->
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: Child incorrectly cascade deleting its parent...
PostPosted: Mon Jun 19, 2006 3:07 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
For some reason my child objects have started cascade deleting their parent objects, rather than just removing themselves from the parent's child collection.
This is obviously a big problem as the child's siblings no longer have a valid parent.
I'm sure I must have just done something silly in my mapping files (see below).

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping
  xmlns="urn:nhibernate-mapping-2.0"
  assembly="MyAssembly"
  namespace="MyNamespace"
  default-cascade="all"
  default-lazy="true"
>
  <class
    name="Parent"
    dynamic-update="true"
    lazy="false"
  >
    <id name="ID" access="nosetter.lowercase-underscore">
      <generator class="assigned" />
    </id>
    <property name="Name" />
    <set name="Children" access="MyAccessor, MyAssembly" inverse="true">
      <key column="ParentID" />
      <one-to-many class="Child" />
    </set>
  </class>
 
  <class
    name="Child"
    dynamic-update="true"
    lazy="false"
  >
    <id name="ID" access="nosetter.lowercase-underscore">
      <generator class="assigned" />
    </id>
    <many-to-one name="Parent" class="Parent" column="ParentID" access="MyAccessor, MyAssembly" not-null="true" />
  </class>
</hibernate-mapping>


Nathan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 11:40 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
you have default-cascaed set to all. All = Save, Update, Delete. if you use this setting, you will have to "override" the setting in the many-to-one with something else, most likely cascade="none" or maybe cascade="save-update"

-devon


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.