-->
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.  [ 2 posts ] 
Author Message
 Post subject: flushing and updating
PostPosted: Thu Oct 05, 2006 1:21 pm 
Newbie

Joined: Thu Oct 05, 2006 1:14 pm
Posts: 4
I have an issue with hibernates flushing and updating.

We have an entity named USER
as well, we are doing some audit tracking

To do our audit tracking, we have extended org.hibernate.event.def.DefaultFlushEntityEventListener

and then we have overridden

public void onFlushEntity(FlushEntityEvent event) throws HibernateException
{
if (event.getEntity() instanceof ChangeAuditable)
{
if (currentUser.get() != null)
{
ChangeAuditable ca = (ChangeAuditable) event.getEntity();
Integer id = currentUser.get().getUserId();
ca.setChangeUserId(id);
}
}
super.onFlushEntity(event);
}

we then make a call to updateUser(..................)

We do not want to set the field changeUserId if no actual changes were made to the user object, how and where could we check for this, we have tried dirtyCheck, but that throws a nullpointerexception.

Any help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Use an interceptor instead
PostPosted: Fri Oct 06, 2006 10:20 am 
Newbie

Joined: Tue Oct 03, 2006 5:24 am
Posts: 2
Hi,
If I'm not terribly mistaken, using an interceptor is a simpler solution. Just create an interceptor that extends EmptyInterceptor, and override the onFlushDirty()-method. This is called only when an object has been changed. I believe the documentation has a good example here: http://www.hibernate.org/hib_docs/v3/re ... vents.html

- Trond

_________________
- Trond


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