-->
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: change parent in bidirectional list association
PostPosted: Thu Apr 24, 2008 4:54 am 
Newbie

Joined: Mon Mar 17, 2008 4:43 am
Posts: 3
Hi,

I have a bidirectional parent child relation with an indexed collection. My mapping is as follows:

Code:
<hibernate-mapping>
    <class name="foo.model.Task" table="tasks">
        <id name="id">
            <generator class="native" />
        </id>
       
        <version name="version" access="field" />
   <many-to-one name="parent" column="project_id" class="foo.model.Project" insert="false" update="false" not-null="true" />
   
   </class>       
</hibernate-mapping>


<hibernate-mapping>
    <class name="foo.model.Project" table="projects">
        <id name="id">
            <generator class="native" />
        </id>
               
        <version name="version" access="field" />
       
        <list name="tasks" cascade="all-delete-orphan" inverse="false" access="field">
       <key column="project_id" not-null="true" />
       <list-index column="ordr" />
       <one-to-many class="foo.model.Task" />
        </list>
    </class>       
</hibernate-mapping>



I have also provided the necessary helper methods within my model:

Code:
    public void addTask(Task task) {
        task.setParent(this);
        tasks.add(task);
    }
   
    public void removeTask(Task task) {
        task.setParent(null);
        tasks.remove(task);
    }


I want to change the parent of the child and assign it to another. Something like this:

Code:
Task task = getTaskFromSomewhere();
initialParent.removeTask(task);
newParent.addTask(task);


This snippet seems to perform two queries. One delete to remove the task form the first parent's collection and then an insert to add it to the new one. Seems a bit of reduntant to me since there already is a record for it in the database so an update would ne fine. I understand that since I have mapped the many-to-one part of the relation with insert="false" and update="false" is the reason why I am not getting the update I am looking for. Is there a workaround for it or I just have to compromise with the delete and insert?

Thank you in advance,
Argyro


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.