-->
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.  [ 1 post ] 
Author Message
 Post subject: MergeEventListener updates all objects in object-tree
PostPosted: Tue Dec 18, 2007 8:44 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
Hibernate version: 3.2.5.ga
Hibernate EntityManager version: 3.3.1.ga
Hibernate Annotations version: 3.3.0.ga

Name and version of the database you are using: Oracle 10g

Hi!

I'm using the following MergeEventListener to set my fields for userCre, timeCre, userUpd, timeUpd. The fields indicate when and from who the record was inserted or last updated.

Code:
public class DefaultMergeEventListener implements MergeEventListener {

   private static final long serialVersionUID = 1L;

   private final Logger log = new Logger(getClass());

   public void onMerge(MergeEvent e) throws HibernateException {
      if (e.getOriginal() instanceof Base) {
         updateRecord((Base) e.getOriginal());
         log.debug("update timestamp and userstamp for base record");
      }
   }

   public void onMerge(MergeEvent e, Map arg1) throws HibernateException {
      if (e.getOriginal() instanceof Base) {
         updateRecord((Base) e.getOriginal());
         log.debug("update timestamp and userstamp for base record");
      }
   }

   public void updateRecord(Base record) {
      // existing record
      if (record.getId() != null) {
         // TODO: updates appUser and time of every object in an object-tree
         // causes to update all objects
         record.setUserUpd(BasePlugin.getDefault().getAppUser());
         record.setTimeUpd(new Date());

         // new record
      } else {
         record.setUserUpd(null);
         record.setTimeUpd(null);

         if (record.getUserCre() == null)
            record.setUserCre(BasePlugin.getDefault().getAppUser());

         if (record.getTimeCre() == null)
            record.setTimeCre(new Date());
      }
   }
}


My problem is the following: If I have a large object tree and I make a merge on the top object, all other objects of the tree gets updated. This can take a long time, because the object tree can have hundrets of objects.

So my question: How can I update my timestamps and userstamps properly? I would need something to set the stamps only on dirty objects.

Regards,

Chris.


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

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.