-->
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: delete-on-orphan
PostPosted: Thu Apr 01, 2004 1:52 am 
Newbie

Joined: Tue Feb 03, 2004 1:49 pm
Posts: 16
i am using the built hibernate 2.1.2.

I have a association parent-child.

class com.Parent mapping:
Code:
     

  <bag
            name="childs"
            lazy="true"
            inverse="true"
            cascade="all-delete-orphan"
        >

              <key
                  column="parent_fk"
              />

              <one-to-many
                  class="com.Child"
              />
        </bag>

and,

class com.Child mapping:
Code:
        <many-to-one
            name="parent"
            class="com.Parent"
            cascade="save-update"
            outer-join="auto"
            update="true"
            insert="true"
            column="parent_fk"
            not-null="true"
        />



Using hibernate 2.1.2 and mysql.
The java code:

Code:
... get child from database
...
Parent oldParent = child.getParent();
Parent newParent = ... from database;
oldParent.getChilds().remove(child);
newParent.getChilds().add(child);
child.setParent(newParent);
...
save the child.


The above code failed with "deleted object would be re-saved by cascade".

But, if I change the mapping from "all-delete-orphan" to "all" in com.Parent mapping.

Everything works.

Why??

_________________
mzoom@homealone


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 4:15 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
all-delete-orphan delete orphaned children (is removed from the association link)
So this is expected

_________________
Emmanuel


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.