-->
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.  [ 2 posts ] 
Author Message
 Post subject: Can't remove an object from a Set
PostPosted: Fri Feb 09, 2007 8:42 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 9:54 am 
Beginner
Beginner

Joined: Fri Nov 24, 2006 10:33 am
Posts: 42
Fixed it. I just needed to wrap the DAO in a transactionProxy in my Spring config, or call flush() if I wasn't using Spring. Otherwise, none of the changes were being written to the DB.


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

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.