-->
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: Automatically inject current_time into audit fields on save?
PostPosted: Fri Dec 12, 2008 10:16 am 
Newbie

Joined: Thu Dec 11, 2008 7:19 pm
Posts: 1
In most of our tables, we maintain CreateDate and ModifyDate fields to provide minimal auditing of row changes. Because we cannot trust that the machine executing the query has the correct date/time, we rely on the database server for current date/time.

I am seeking a best practice on how to update these field values on the save and update of an entity. I have come up with the following options thus far. During SaveOrUpdate :

1) Somehow intercept the INSERT or UPDATE query statement and set CreateDate/ModifyDate = current_time(). This is optimal since it would require just 1 database call.

2) Make one database call to retrieve current_time(). Then in an interceptor, find CreateDate/ModifyDate parameters if they exist and update the datetime value. Make a 2nd database call to save or update.

3) Use database triggers to update CreateDate and ModifyDate. I'm not a huge fan of going with triggers, since it requires more database management to ensure that they are properly configured on every table.

Is option 1) even possible? Or is there a better way altogether?


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.