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.  [ 4 posts ] 
Author Message
 Post subject: Audit Interceptors
PostPosted: Wed Sep 17, 2008 11:38 pm 
Newbie

Joined: Wed Sep 17, 2008 11:32 pm
Posts: 2
Hi,

I want to automatically add some audit information when saving data (create_user, create_date, update_user, update_date, etc.).

I've seen some example of using an intercepter to add this information to persistant classes.

No problem there.

My question is this: is there a way to automatically add audit information to relationship tables?

Since the relationships are not actually modelled as entities the intercepter never get's fired for them.

Is there a clean way to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 3:11 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
The interceptor is fired not for the relationship, but for it's owner. Say, an order object has line items, then if you add a line item to the order, the relationship from order to it's line items changes. If you modelled the order to have a collection of line items (Set, List), you will get the previous state of the variable holding the collection, and then you can call:

Code:
PersistentCollection col = (PersistentCollection)previousState[i];
Serializable s = col.getStoredSnapshot();   

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 7:32 am 
Newbie

Joined: Wed Sep 17, 2008 11:32 pm
Posts: 2
Thanks Carlo.

Once I have the persistent collection is there a way to add audit information to it?

Or is the pattern to update the parent audit information whenever a relationship is modified?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 5:07 pm 
Newbie

Joined: Sun May 08, 2005 12:26 pm
Posts: 10
Hi Carlo,

it seems as if you have found an answer to your own question in http://forum.hibernate.org/viewtopic.php?t=985118 - would be nice if you could give some more details!

Given the "stored snapshot", how can one figure out the changes? Does it work for collections of entities only? Than what about collections of (composite) elements (-> @CollectionsOfElements, @Embeddable) - can they also be handled that way?

Regards
Burkhard


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