8 Replies Latest reply on Oct 28, 2005 4:43 PM by Emmanuel Bernard

    Some listeners not called...

    Atanas Todorov Newbie

      I'm trying to register several hibernate listeners under JBoss 4.0.3.

      In my hibernate.cfg.xml I've defined:

      <hibernate-configuration>
       <session-factory>
       <listener type="flush-entity" class="sirma.biz.TheFlushEntityListener"/>
       <listener type="load" class="sirma.biz.TheLoadListener"/>
       <listener type="save" class="sirma.biz.TheSaveListener"/>
       <listener type="delete" class="sirma.biz.TheDeleteListener"/>
       <listener type="dirty-check" class="sirma.biz.TheDirtyCheckListener"/>
       ...
      


      where

      public class TheFlushEntityListener extends DefaultFlushEntityEventListener
      public class TheLoadListener extends DefaultLoadEventListener
      ...
      


      JBoss instantiates all the configured listener classes at deploy-time. But it only calls the methods of the "load" listener. (The way I test this is via overriding all protected and public methods of the super classes and logging something before calling super.theMethod(...), but none of them is called, except for TheLoadListener.)

      What might be the reason?


        • 1. Re: Some listeners not called...
          Atanas Todorov Newbie

          I forgot to mention that I'm using EJB 3.

          • 2. Re: Some listeners not called...
            evrim ulu Newbie

            Use @EntityListener() instead. Search for documentation inside Hibernate EJB3 Annotation documentation.

            • 3. Hibernate event listeners
              Jana Parvanova Newbie

              Hi!
              Is is possible at all to use Hibernate event listeners with EJB3?

              • 4. Re: Some listeners not called...
                Jana Parvanova Newbie

                It seems so far listeners cannot be overridden. I see the following in the org.hibernate.ejb.EventListenerConfigurator:

                public void setProperties(Properties properties) {
                 this.properties = properties;
                 if ( properties.containsKey( HibernatePersistence.JACC_ENABLED ) ) {
                 isSecurity = true;
                 }
                 //TODO check whether there is an event listener overriding
                 }
                
                 public void configure() {
                 //some initial work
                 ValidateEventListener validateEventListener = null;
                 if (isValidator) {
                 validateEventListener = new ValidateEventListener();
                 }
                 //handle callbacks for all classes
                 //TODO exclude pure hbm file classes?
                 EntityCallbackHandler callbackHandler = new EntityCallbackHandler();
                 configuration.buildMappings(); //needed to get all the classes
                 Iterator classes = configuration.getClassMappings();
                 while ( classes.hasNext() ) {
                 PersistentClass clazz = (PersistentClass) classes.next();
                 callbackHandler.add( clazz.getMappedClass() );
                 }
                
                 EventListeners listenerConfig = configuration.getEventListeners();
                
                 //Action event
                 //EJB3-specific ops listeners
                 listenerConfig.setFlushEventListeners( new FlushEventListener[] { EJB3FlushEventListener.INSTANCE } );
                 //EJB3-specific ops listeners
                 listenerConfig.setAutoFlushEventListeners( new AutoFlushEventListener[] { EJB3AutoFlushEventListener.INSTANCE } );
                 listenerConfig.setDeleteEventListeners( new DeleteEventListener[] { new EJB3DeleteEventListener( callbackHandler ) } );
                 listenerConfig.setFlushEntityEventListeners( new FlushEntityEventListener[] { new EJB3FlushEntityEventListener( callbackHandler ) } );
                 listenerConfig.setMergeEventListeners( new MergeEventListener[] { new EJB3MergeEventListener( callbackHandler ) } );
                 listenerConfig.setPersistEventListeners( new PersistEventListener[] { new EJB3PersistEventListener( callbackHandler ) } );
                 listenerConfig.setSaveEventListeners( new SaveOrUpdateEventListener[] { new EJB3SaveEventListener( callbackHandler ) } );
                 listenerConfig.setSaveOrUpdateEventListeners( new SaveOrUpdateEventListener[] { new EJB3SaveOrUpdateEventListener( callbackHandler ) } );
                ................
                


                • 5. Re: Some listeners not called...
                  evrim ulu Newbie

                  I'm not too much experienced with hibernate but if you'r implementing ejb3, you shouldn't bound yourself with hibernate, you may want to try other ejb3 implementations in future(JDO, Oracle Toplink etc). I feel you'r trying to avoid re-implementing your listeners but, it seems it's the best choice here to re-implement them with @EntityListener().

                  evrim.

                  • 6. Re: Some listeners not called...
                    Jana Parvanova Newbie

                    evrim,
                    You are right on this. But ejb3 is not official anyway at this time. Our project is planned to be rather long so I hope that at some point ejb3 would provide some more convenient mechanisms to implement audit functionality in which case we will of course consider pure ejb3 approach.

                    • 7. Re: Some listeners not called...
                      evrim ulu Newbie

                      Hm, i'm having the same problem, ejb3 don't have instance based security. Hibernate have some type of Class level security(org.hibernate.secure.JACCPreLoadEventListener) but its not sufficient. I've tried to implement acegi-like acl's but failed most of the cases like read permissioning. EJB3 have only PostLoad conditional, and doesn't have PreLoad. :(

                      • 8. Re: Hibernate event listeners
                        Emmanuel Bernard Master

                         

                        "Jana" wrote:
                        Hi!
                        Is is possible at all to use Hibernate event listeners with EJB3?

                        Not yet but I plan to open this soon