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.