-->
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.  [ 4 posts ] 
Author Message
 Post subject: Best Practice for intercepting changes to a child collection
PostPosted: Tue May 09, 2006 10:07 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
I have a object with a collection on it. When I remove or add an element to the collection and call update(object), onFlushDirty never gets called.

My understanding is that is the correct behavior, which is fine, but what is the best practice for detecting changes to the child collections?

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 10:30 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
What is the cascade setting you have set up for the collection? If you're only updating the parent object and not the children, bad cascade settings may be causing this behavior.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 10:42 pm 
Regular
Regular

Joined: Sat Oct 18, 2003 11:53 am
Posts: 55
Here is the mapping:

Code:
<hibernate-mapping>
    <class name="com.cri.db.hibernate.LineItemImpl" table="line_items">

        <id name="lineItemId" column="line_item_id" type="java.lang.Integer">
            <generator class="native"/>
        </id>

        <property column="comments" length="500" name="comments" type="java.lang.String"/>
        <property column="quantity" length="10" name="quantity" type="java.lang.Double"/>
        <property column="create_date" length="16" name="createDate" type="java.util.Date"/>

        <!-- The line item drives the inventory, so we need to be able to save the changes -->
        <many-to-one column="product_id" name="product" class="com.cri.db.hibernate.Product" not-null="true" fetch="join"/>

        <many-to-one column="event_id" name="event" class="com.cri.db.hibernate.Event" not-null="true" fetch="join"/>

        <set name="providers" table="line_items_providers_map" fetch="join">
            <key column="line_item_id"/>
            <many-to-many class="com.cri.db.hibernate.Provider" column="provider_id"/>
        </set>
    </class>
</hibernate-mapping>


..all I am doing is removing a "provider" from the set.

Does it matter that I am calling session.merge? Should I use an event listener for that session method instead?

Matt


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 11:31 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
The default behavior of collections is cascade="none". This means that you must explicitly save child objects in addition to the parent. You haven't posted the code you're executing, but I assume from your description this is what you're doing. Try setting cascade="all" on the <set> and see if that gives you the behavior you want?


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