-->
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: many-to-many save problem
PostPosted: Thu Feb 21, 2008 4:06 pm 
Newbie

Joined: Thu Jan 31, 2008 1:48 pm
Posts: 11
I have many-to-many unidirectional relationship set up as follow

The Adp.hbm.xml hibernat mapping file for Adp class has following many-to-many association defined.

Code:
        <set
         name="tags"
         lazy="true"
         table="t_a_custom_tag"
         cascade="all"
         >
            <key>
                <column name="AdpId"/>
            </key>
            <many-to-many column="CustomFieldId" class="com.CustomField" />
        </set>


It is unidirectional so CustomField class does not define the association on other side.

When I save the Adp object, hibernate first deletes all the tags from t_a_custom_tag table for given Adp and then reinsert them all. I tried cascade 'all-delete-orphan' but it behaves the same way.

Here are the queries that hibernate generates when saving Adp object.

Code:
delete from t_a_custom_tag where AdpId=?
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)
insert into t_a_custom_tag (AdpId, CustomFieldId) values (?, ?)


My tags collection has not been changed, i'm just saving the screen withougt any modification but it generates these redundant queries that i'm trying to optimize. I would appreciate your help in this regard.

Thanks in advance.


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.