-->
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.  [ 5 posts ] 
Author Message
 Post subject: best hook for "lastUpdateDate" timestamping?
PostPosted: Wed Apr 07, 2004 2:22 pm 
Newbie

Joined: Tue Dec 16, 2003 8:34 am
Posts: 15
Hello,

Well I've been using Hibernate for a couple of years, but my problem doesn't seem to thematically "fit" into one of the other forums, so I guess I'll have to post it here ;)

In Hibernate 2.1.2, I have a persistent class that has a persistent property: "lastUpdateDate". The semantic of this property is the conventional one: every time there is a change to some persistent properties in this class, when those changes are propogated (committed) to the database, the "lastUpdateDate" property and corresponding column value should be updated with the current timestamp.

The problem I'm having is finding a single hook that covers all of the different Hibernate methods for propogating changes to the database.

For instance, if I try to implement my lastUpdateDate functionality in the Lifecycle methods, onSave() and onUpdate(), I don't catch changes to my persistent class that are propogated to the database with this construct:

Session aSession = //assume we get a Session
PersistentObject aPersistentObject = // assume we fetch this object in aSession
Transaction aTransaction = aSession.beginTransaction();

aPersistentObject.setPersistentProperty(aNewValue);

aTransaction.commit();

In this scenario, aNewValue is propogated to the db for "persistentProperty", but none of the Lifecycle methods are ever called.

Is there a lower (than the Lifecycle methods) level hook where I can implement my timestamping?

thanks,

joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 4:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Interceptor.onFlushDirty()


Top
 Profile  
 
 Post subject: Interceptor.onFlushDirty() has same problem
PostPosted: Wed Apr 07, 2004 6:00 pm 
Newbie

Joined: Tue Dec 16, 2003 8:34 am
Posts: 15
Steve,

thanks for the tip. However, onFlushDirty is not getting called in the scenario that I outlined in my original post. It gets called when I Session.save() or Session.update(), but not on Transaction.commit().


thanks,

joe


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 07, 2004 6:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Untrue.

Interceptor.onFlushDirty() is called *whenever* Hibernate detects an entity to have been modified for which it needs to synchronize state with the DB.

This is exactly how I implement this functionality now.

It does work


Top
 Profile  
 
 Post subject: my mistake
PostPosted: Wed Apr 07, 2004 6:30 pm 
Newbie

Joined: Tue Dec 16, 2003 8:34 am
Posts: 15
Steve,

ok, I read my logs wrong. I thought onFlushDirty would be called on the initial Session.save(). But it looks like it doesn't get called as a result of the save() (insert), only as a result of the Transaction.commit() (update).

thanks,

joe


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