-->
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 Logging
PostPosted: Thu Jun 22, 2006 12:50 am 
Newbie

Joined: Thu Jun 22, 2006 12:22 am
Posts: 9
Hi ,

Please help me with this requirement in Audit Logging.

I'm using life cycle methods of interceptor for logging.

I'm using Spring Transaction and the method i'm invoking to persist the entity object is getHibernateTemplate().merge().

Before calling this method, i need to set a property to the entity object. But this property is an unmapped property. i.e.; it’s not present in hbm file or in table.[This is possible because I’m extending the data class from my class which has this property and getters/setters for this property.]

When the life cycle methods are triggered, this unmapped property value, the old values and new values, I want to insert to my Audit Table.

I have implemented Interceptor and the life cycle methods onSave, FlushDirty, findDirty

The issue here is the value of the unmapped property which I’m setting is becoming null in the entity object passed to OnSave method.

Is there any work around for this?

Thanks In Advance
Chandrasekhar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 22, 2006 1:08 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes: don't use merge. When merge is given a transient version of a persistent object, it loads the persistent version in order to do the merge. This is the version that your interceptor is seeing. If you merged it yourself, or even better, work only with peristent or detached objects (and never transient versions of peristent objects), and then call update/saveOrUpdate, then the object that your interceptor sees will be the one with the unmapped property.

I think.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 1:09 am 
Newbie

Joined: Thu Jun 22, 2006 12:22 am
Posts: 9
Hi,

Thanks a lot the reply.

When I tried using saveOrUpdate, in the Interceptor call back

onFlushDirty method

[ onFlushDirty(Object entity, Serializable id, Object[]

newValues, Object[] oldValues, String[] properties, Type[] types) ],

the oldValues Object array is coming null.

But i need old values also for logging.

Is there any other alternative.

Please clarify another doubt,when is the findDirty call method invoked?

Thanks In Advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 23, 2006 1:23 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Hmm. I'm not sure about the ins and outs of interceptors. Would switching to events be feasible? There's a MergeEventListener that's bound to give you exactly the functionality you need...

_________________
Code tags are your friend. Know them and use them.


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.