-->
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.  [ 1 post ] 
Author Message
 Post subject: interesting cascade behaviour in recursive relationshiops
PostPosted: Mon Apr 12, 2004 7:33 am 
Newbie

Joined: Thu Jan 29, 2004 3:52 pm
Posts: 16
Hi,

I have come across an interesting problem. Take a look at the simple mapping below. Class A is in recursive relationship with it self and save-update cascade option is turned on. A is also in parent/child relationship with class B with the same cascade option turned on.

The problem I am experiencing is when a remote client in a detached graph adds x many Bs to an A and saves it back on the server side. I am not sure if this happens only with detached graphs.

Back to the problem. There are two scenarios. In the first one when x many Bs are added to a leaf A then everything works as expected. However, in a second scenario if x many Bs are added to a non-leaf A then save is cascaded to all the ancestors of A. Thus in the end one ends up with <number of A's ancestors>*<number of x> many object in a database.

Is this the proper behaviour? If yes, how do I add Bs to non-leaf A and avoid having cascading add of Bs to A's ancestors but at the same time keep cascade semantics of A's recursive relationship to itself?

All the best,
Vladimir

Code:

<class name="A" table="A">
        <id name="id" unsaved-value="0" column="id" type="long">
            <generator class="increment"/>
        </id>
        <set name="bs" lazy="false" inverse="true" cascade="save-update">
            <key column="parent"/>
            <one-to-many class="B"/>
        </set>
        <set name="children" lazy="false" inverse="true" cascade="save-update">
            <key column="parent"/>
            <one-to-many class="A"/>
        </set>
        <many-to-one name="parent" class="A"/>       
    </class>
   
    <class name="B" table="B">
       <id name="id" unsaved-value="0" column="id" type="long">
            <generator class="increment"/>
      </id>             
      <many-to-one name="parent" class="A"/>               
    </class>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.