-->
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.  [ 3 posts ] 
Author Message
 Post subject: Update parent-child records
PostPosted: Mon Feb 13, 2006 11:45 am 
Newbie

Joined: Mon Feb 13, 2006 11:12 am
Posts: 4
Hi

I'm having a problem trying to update a parent-child relationship using a composit-id object, the old records are not removed from the table and they are left without parent's reference, though there is a cascade="all-delete-orphan" on the association.

This is the situation, the parent Table is called Offer and the child RateCode, I save a previous existing Offer adding 2 new RateCodes. The new RateCodes are added all right but the old ones are not removed from the RateCode table, instead the FKOFFER value is set to null. There is no exception, but I'd like to remove those unreferenced records when saving. Please help!

Million thanks in advance!

j a p

Hibernate version:
3.1.2
Mapping documents:
Code:
<class name="Ffpoffer" table="FFPOFFER" where="(deleted is null)">
...........
<set name="ffpofferratecodeSet" cascade="all-delete-orphan">
       <key column="FKOFFER"/>
       <one-to-many class="Ffpofferratecode"/>
</set>
</class>

<class name="Ffpofferratecode" table="FFPOFFERRATECODE">
        <composite-id name="id" class="OfferRateCodeKey">
           <key-many-to-one name="rateCode" column="FKRATECODE" class="com.domain.bmdev.RateCode" />
           <key-many-to-one name="ffpoffer" column="FKOFFER" class="Ffpoffer" />
        </composite-id>
</class>



public class Ffpofferratecode
    implements Serializable
{

    private OfferRateCodeKey id;
    public Ffpofferratecode()
    {}
    public OfferRateCodeKey getId() {
              return id;
    }
    public void setId(OfferRateCodeKey id) {
              this.id = id;
    }
}

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 12:03 pm 
Regular
Regular

Joined: Tue Nov 29, 2005 12:31 pm
Posts: 75
Hi,

1.

<set name="ffpofferratecodeSet" inverse="true" cascade="all-delete-orphan">
<key column="FKOFFER"/>
<one-to-many class="Ffpofferratecode"/>
</set>

2.

Before adding the new 2 new RateCodes :

ffpoffer.getFfpofferratecodeSet.clear();

If i doesn't work, provide more details.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 12:11 pm 
Newbie

Joined: Mon Feb 13, 2006 11:12 am
Posts: 4
It worked perfect, thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.