-->
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.  [ 3 posts ] 
Author Message
 Post subject: Best approach for record level auditing
PostPosted: Thu Jun 09, 2005 6:21 am 
Newbie

Joined: Tue Mar 30, 2004 1:06 pm
Posts: 4
Hi,
I would like to know your opinion about the best approach using Hibernate for auditing a record. In other words, I have a table with the following audit fields:
    Date-Created (date)
    Date-Updated (date)
    Created-By (date)
    Updated-By (date)

and I want to update these fields when a record is created/updated.

I want to use a db-agnostic approach (no triggers). I understand that Interceptors should be the right tool here.
Are there better approaches?

Thanks
Luciano


Top
 Profile  
 
 Post subject: record level auditing
PostPosted: Thu Jun 09, 2005 6:46 am 
Newbie

Joined: Wed Mar 23, 2005 9:33 am
Posts: 11
Another possible approach is to use an AOP proxy. If you're already using Spring this is simply a matter of implementing an interceptor (base classes that do most of the heavy lifting are already provided) and wiring it up in the application context.

See http://www.springframework.org/docs/reference/aop.html


Top
 Profile  
 
 Post subject: Audit at record level
PostPosted: Thu Jun 09, 2005 10:19 pm 
Newbie

Joined: Wed Apr 20, 2005 10:57 pm
Posts: 6
Do you want a History Object. The fields you have will have is not sufficient for auditing purpose. If you want the entire record to be audited the you create a corresponding HistoryObject which has the same fields as the original one and an extra attribute objectId which holds the id of the original object. When you save the original object you also save the history object. The HistoryObject will have a constructor which takes the the original object and copies all the fields from the original to the History fields and the ID of the original to the objectID of the History object.

I wrote a generator which does this for me automatically. In this approach you can even save the relationships(i.e if you wanted or selectively save related objects). This works really good

eg
class User{

Long id;
String a1;
String a2;

// createdDate,createdBy, updateDate, updatedBy

// get and set methods

}

class UserHist{
Long id;
Long objectId;
String a1;
String a2;

public UserHist(User u)
{

this.objectId = u.id;
this.a1 = u.a1;
this.a2 = u.a2;
// createdDate,createdBy, updateDate, updatedBy

}
}

public class UserDAO
{
void save(User u){

saveorUpdate(u);
UserHist uh = new UserHist(u);
saveorUpdate(uh);
}

}


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