-->
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: Save Or Update Event Listener help
PostPosted: Fri Jul 20, 2007 9:58 am 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18
I am trying to implement (can you guess?) an auditing function. When I save or update any object I would like to set the userId of the person who made the change and the date. All tables will have these fields.

So far I have this in my Spring applicationContext-dao.xml:

Code:
<bean id="sessionFactory" ...>
<property name="eventListeners">
  <map>
   <entry key="save-update"><ref local="saveOrUpdateListener" /></entry>
   </map>
  </property>
</bean>
<bean id="saveOrUpdateListener" class="com.myco.myapp.dao.SaveOrUpdateListener" />


And this is my class:

Code:
public class SaveOrUpdateListener extends DefaultSaveOrUpdateEventListener
{
  public void onSaveOrUpdate(SaveOrUpdateEvent event) throws HibernateException
   {
      System.out.println("Hello from SaveOrUpdateListener!!!");
      super.onSaveOrUpdate(event);
   }
}


The class is not being called when I save or update. I am not sure about the name of the listener in applicactionContext-dao.xml. All the examples on the web use the DefaultLoadEvenListener and use "load" as the name. I've tried using "save", "save-or-update", "save-update", nothing works.

Assuming I get this working I am not too sure exactly how to update the two columns, userId and dateMod. Using an Interceptor it was quite easy. You just cycle through the property names and set the ones you want. But my Interceptor didn't work for updates, only inserts (saves) so I was told to use EventListener instead.

Has anyone ever successfully implemented this?

Many thanks,
Bob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 8:19 am 
Newbie

Joined: Wed Jan 23, 2008 7:45 am
Posts: 14
Location: Pune,India
You can do this even in an Interceptor by using the onFlushDirty function.

_________________
Harshal Vaidya


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 08, 2008 4:06 pm 
Newbie

Joined: Fri Feb 08, 2008 3:52 pm
Posts: 1
Having the same problem with the exact same setup as the example you provide. Discovered that entering the listener entry twice fixed it. Appears to be a bug - might be fixed with a more current version - not sure what version I'm using.

<property name="eventListeners">
<map>
<entry key="save-update"><ref local="eventListener" /></entry>
<entry key="save-update"><ref local="eventListener" /></entry>
</map>
</property>


Maybe this will help somebody out.


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.