-->
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: Detecting changes in in one-to-many association
PostPosted: Thu Dec 10, 2009 10:17 am 
Newbie

Joined: Mon Oct 26, 2009 8:28 am
Posts: 2
Hello,

the last days i've been working on importing a tree structure using hibernate. The source is some CSV which will be imported periodically. The import works fine and what i need to do now is to log changes in the tree structure. Of course this could be done in the import code where the CSV gets transformed into a tree, but i am wondering if it possible to do this by using an EmptyInterceptor. By overriding #onSave and #onDelete i could detect, when an entity gets added or removed. By overriding #onFlushDirty i can detect changes of properties, but what i fail to log is when already existing elements gets moved in the hierarchy. As i am quite new to hibernate it may be simple, but i couldn't find there any information in the docs. So my questions is, how i could detect changes in associations.

Thanks in advance for any ideas!

GLA


Top
 Profile  
 
 Post subject: Re: Detecting changes in in one-to-many association
PostPosted: Tue Dec 15, 2009 6:58 am 
Newbie

Joined: Mon Oct 26, 2009 8:28 am
Posts: 2
Probably it's better to illustrate my question with some code. The entity class looks like this:

Code:
public class ForeignArticleType extends ForeignType {

        ....
   private Set<ForeignArticleType> subArticleTypes = null;
      
       ...
       .... various get/set methods
   
}


It is a article type, that holds a collection of sub types (subArticleTypes). The mapping looks like this:

Code:
<class name="ForeignArticleType">
     <id name="id" column="FOREIGNARTICLETYPE_ID">
        <generator class="native"/>
     </id>

       ... various properties

     <set name="subArticleTypes" cascade="save-update,persist,delete" lazy="false">
        <key column="PARENT_ID"/>
        <one-to-many class="ForeignArticleType"/>
     </set>

        ....

  </class>


Given the following situation: I have three article types with the ids 1, 2, 3, 4, whereas element 2 is a child of 1 and and 4 a child of 3 - Element 1 holds element 2 in the collection subArticleTypes. All elements are persisted. Then i add element 2 in 3 as sub type. How do i track this with an interceptor? EmptyInterceptor#onFlushDirty doesn't notice it.

Thanks in advance!

GLA


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.