-->
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.  [ 11 posts ] 
Author Message
 Post subject: pre-update event listener not firing
PostPosted: Fri Jan 20, 2006 11:05 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
OK, I've done a search on the forum, and a few people have had questions about events, but not this one.

I am working with Hibernate embedded in JBoss.

I have a multipurpose event listener, configured by

Code:
         <event type="pre-update">
            <listener class="com.fcl.util.HibernateEventListener"/>
         </event>
         <event type="post-commit-update">
            <listener class="com.fcl.util.HibernateEventListener"/>
              <listener class="org.hibernate.lucene.event.LuceneEventListener"/>
         </event>
         <event type="post-commit-insert">
            <listener class="com.fcl.util.HibernateEventListener"/>
              <listener class="org.hibernate.lucene.event.LuceneEventListener"/>
         </event>
         <event type="post-commit-delete">
            <listener class="com.fcl.util.HibernateEventListener"/>
              <listener class="org.hibernate.lucene.event.LuceneEventListener"/>
         </event>


(I'm using Lucene to add searchability)

My own code is in com.fcl.util.HibernateEventListener.

The 3 post-commit-? events are firing - I can my logging statements in the log, but the pre-update event is not being fired. My listener (only the method I'm talking about shown) looks like this:

Code:
public class HibernateEventListener implements PostDeleteEventListener,
      PostInsertEventListener, PreUpdateEventListener, PostUpdateEventListener, Initializable
{

   ...

   public boolean onPreUpdate(PreUpdateEvent event)
   {
      final Object entity = event.getEntity();
      System.out.println("About to update " + entity);
   }
}


I'm planning to implement security and auditing by hooking into this event, so it's going to be a major cornerstone of our application.

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 11:19 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
It is just a thought but maybe the same as http://opensource2.atlassian.com/projec ... wse/EJB-93


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 11:43 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
Thanks, but that would involve annotations on every persistent entity to implements an auditing and security structure.

What I'm trying to do is adding a central hook into the pre-update event, so that I see all updates to all entities.

A rule-based security and auditing object then decides whether that entity is subject to access control and/or auditing, and performs the necessary processing.

Hibernate is calling my other methods, and I can happily log post-update events, post-insert events etc. It's actually quite cool to be able to hook into things like that, just that the event I want isn't working for me!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 4:52 pm 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Good luck getting an answer. If you look through the forum, you'll see most event-related questions just get sucked into a black hole for some reason.

I can't be of much help to you. But just FYI, I'm not using JBoss, but my onPreUpdate events seem to be working for the moment. However, only when I configure it declaritively (like you appear to be doing). If I try configure it programatically, they don't fire. I'm using Hibernate 3.1.1.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 5:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
It appears to get called correctly from the code. Does the listener get registered correctly (any errors)?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 9:27 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
Thanks for the replies. Yes, it's being registered. From server.log:

Code:
2006-01-23 13:17:48,468 DEBUG [org.hibernate.cfg.Configuration] Event listeners: save-update=com.fcl.util.HibernateEventListener
2006-01-23 13:17:48,468 DEBUG [org.hibernate.cfg.Configuration] Event listeners: pre-update=com.fcl.util.HibernateEventListener
2006-01-23 13:17:48,468 DEBUG [org.hibernate.cfg.Configuration] Event listeners: post-commit-update=com.fcl.util.HibernateEventListener, org.hibernate.lucene.event.LuceneEventListener
2006-01-23 13:17:48,468 DEBUG [org.hibernate.cfg.Configuration] Event listeners: post-commit-insert=com.fcl.util.HibernateEventListener, org.hibernate.lucene.event.LuceneEventListener
2006-01-23 13:17:48,468 DEBUG [org.hibernate.cfg.Configuration] Event listeners: post-commit-delete=com.fcl.util.HibernateEventListener, org.hibernate.lucene.event.LuceneEventListener


It's firing the post update event, I can see my logging line:

Code:
2006-01-23 13:20:18,156 INFO  [STDOUT] Updating <customer><id>27</id><name>Bawtry Buckles</name><address>31 Granville Road</address><city>Bawtry</city><county>Lancashire</county><phoneNumber>019 828 8372</phoneNumber><postCode>BL7 9RJ</postCode>


I should also be seeing a line saying "About to update..."


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 5:48 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
OK, I've downloaded the Hibernate 3.1.1 source, and I've put some debug statements in org.hibernate.action.EntityUpdateAction.preUpdate()

What's coming out is

Code:
09:30:36,515 INFO  [STDOUT] In hibernate preUpdate()
09:30:36,515 INFO  [STDOUT] Got session SessionImpl(PersistenceContext[entityKeys=[EntityKey[entity.Customer#22]],collectionKeys=[]]
;ActionQueue[insertions=[] updates=[EntityUpdateAction[entity.Customer#22]] deletions=[] collectionCreations=[] collectionRemovals=[
] collectionUpdates=[]])
09:30:36,515 INFO  [STDOUT] EventListeners = org.hibernate.event.EventListeners@d4c5a0
09:30:36,515 INFO  [STDOUT] Got 1 pre-update listeners
09:30:36,515 INFO  [STDOUT] Listener 1: org.hibernate.validator.event.ValidateEventListener


So yes, the code is calling the configured listeners.

It's just that although the configuration claims that it's adding my listener, it's not in the list when the time comes.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 8:17 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
OK, I've added debug statements to
Code:
org.hibernate.event.EventListeners.setPreUpdateEventListeners(PreUpdateEventListener[] preUpdateEventListener)


And JBoss is configuring it twice.

Once from my XML configuration file, and then it does its own configuration where it sets the pre update listener to be a org.hibernate.validator.event.ValidateEventListener

The problem is that the EventListeners object only has a method for setting the entire stack of listeners. OK, you can get the array, create a new one, copy the old one, add yours, and set it, but JBoss doesn't do that, it just uses what's available.

Surely, like most event handling patterns there should be an addBlahEventListener() call?

Anyway, in my opinion, the problem is with JBoss in the way it configures using the user-supplied XML configuration file, and then stomps on that with its own configuration setup.

I'll post something on the JBoss configuration forum http://www.jboss.com/index.html?module= ... forum&f=61


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 3:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So this is an ejb3/EntityManager thing. See, important piece of information to know ;)

Just post it over on our ejb3 forum http://forum.hibernate.org/viewforum.php?f=9 Emmanuel will see it there. I am not familiar enough with how the EntityManagerFactory configures the internal SessionFactory...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 6:11 am 
Regular
Regular

Joined: Fri Jan 20, 2006 9:38 am
Posts: 61
Location: Notts, UK
I've done that, we'll see if Emmanuel responds. Could you remind him to take a peek at that folder? I've tried to include as much info as I'd like to see if someone were reporting a problem in my code! Thanks.


Top
 Profile  
 
 Post subject: Re: pre-update event listener not firing
PostPosted: Mon Dec 13, 2010 2:50 am 
Newbie

Joined: Tue May 18, 2010 5:39 am
Posts: 19
you may want to read http://anshuiitk.blogspot.com/2010/11/h ... event.html

_________________
AG
http://anshuiitk.blogspot.com


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