Hi
I'm having trouble removing a child object (FieldGroupingValue) from a Set in a parent object (LetterTemplateValue). The child object is correctly removed from the set (I can see this when debugging) but the update doesn't remove the entry in my association table, so the next time I reload the LetterTemplate, it's set still contains the thing I was trying to delete.
Code:
public void removeFieldGroupingsFromTemplate(Integer[] groupingIds, Integer templateId) {
LetterTemplateValue template = findLetterTemplateByPK(templateId); // this has 3 FieldGroupingValue objects in the set at this point
for(int i=0; i<groupingIds.length; i++) {
FieldGroupingValue grouping = (FieldGroupingValue)getHibernateTemplate().get(FieldGroupingValue.class, groupingIds[i]);
template.getFieldGroupings().remove(grouping); // the object is corectly removed from the Java point of view
}
getHibernateTemplate().update(template); // this line doesn't seem to update the association
}
Here's my mapping. I think it's something to do with the definition of the set, but I can't fugure out what.
Code:
<class name="com.lsb.uk.mqs.value.lasernet.LetterTemplateValue" table="LETTER_TEMPLATE">
<id name="templateId" column="ID" unsaved-value="0">
<generator class="sequence">
<param name="sequence">letter_template_id_seq</param>
</generator>
</id>
<property name="templateCode" column="CODE" />
<property name="alwaysGenerate" column="ALWAYS_GENERATE" />
<property name="description" column="DESCRIPTION" />
<set name="fieldGroupings" table="TEMPLATE_FIELD_GROUPING" lazy="true" fetch="join" cascade="all-delete-orphan">
<key column="TEMPLATE_ID"/>
<many-to-many column="FIELD_GROUPING_ID" class="com.lsb.uk.mqs.value.lasernet.FieldGroupingValue"/>
</set>
<property name="lastUpdateUser" column="LAST_MODIFIED_BY"/>
<property name="lastUpdateDate" column="LAST_MODIFIED_ON"/>
</class>
<!-- FieldGroupingValue class -->
<class name="com.lsb.uk.mqs.value.lasernet.FieldGroupingValue" table="FIELD_GROUPING">
<id name="fieldGroupingId" column="ID">
<generator class="sequence">
<param name="sequence">field_grouping_id_seq</param>
</generator>
</id>
<property name="name" column="NAME" />
</class>
Would be very grateful if somebody could point out my mistake.
Richard