-->
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: Problem saving/deleting parent with 2 sets of children
PostPosted: Fri Mar 26, 2004 12:57 pm 
Newbie

Joined: Fri Mar 26, 2004 12:30 pm
Posts: 2
I am having a problem either creating or deleting an object graph where the parent has 2 sets of children, depending on the order in which the child sets are declared in the mapping file.

class A {
Set bChildren;
Set cChildren;
}

Class B {
A parent;
}

Class C {
A parent;
B friend;
}

In the mapping file I have cascade="all-delete-orphan" turned on for both sets of children, inverse="true" for both sets of children, and not-null="true" for the 'friend' reference from C to B.

If I declare in A's mapping file the set of bChildren before the set of cChildren, then Session.save() works but Session.delete() fails with the error:

net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: C.friend

If I declare cChildren before bChildren, then Session.save() fails with the same error.

Is there a way to make Hibernate cascade intelligently in this case or do I need to manually handle the cascading in this particular situation?

I am using Hibernate version 2.1.2.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 3:43 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
mapping

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 26, 2004 4:10 pm 
Newbie

Joined: Fri Mar 26, 2004 12:30 pm
Posts: 2
Here are the mappings for the 3 classes. I do have an 'id' field in the java classes that I did not show originally.


Code:
<class name="A" table="A">
        <id name="id" type="long" unsaved-value="0" >
            <column name="ID" sql-type="NUMBER(22)" not-null="true"/>
            <generator class="sequence">
               <param name="sequence">A_S</param>
            </generator>
        </id>

      <set name="bChildren" inverse="true" cascade="all-delete-orphan">
         <key column="A_ID"/>
         <one-to-many class="B"/>
      </set>

      <set name="cChildren" inverse="true" cascade="all-delete-orphan">
         <key column="A_ID"/>
         <one-to-many class="C"/>
      </set>
</class>

<class name="B" table="B">
        <id name="id" type="long" unsaved-value="0" >
            <column name="ID" sql-type="NUMBER(22)" not-null="true"/>
            <generator class="sequence">
               <param name="sequence">B_S</param>
            </generator>
        </id>
       
        <many-to-one name="parent" column="A_ID"
         class="A" not-null="true"/>
</class>

<class name="C" table="C">
        <id name="id" type="long" unsaved-value="0" >
            <column name="ID" sql-type="NUMBER(22)" not-null="true"/>
            <generator class="sequence">
               <param name="sequence">C_S</param>
            </generator>
        </id>
       
        <many-to-one name="parent" column="A_ID"
         class="A" not-null="true"/>
         
        <many-to-one name="friend" column="B_ID"
         class="B" not-null="true"/>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 27, 2004 5:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
cascade the many-to-one too

_________________
Emmanuel


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.