-->
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: Registering Hibernate 4 listeners, Integrator
PostPosted: Mon May 23, 2016 5:03 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
I have two spring beans - one is my custom event listener implementing three interfaces, second is Hibernate integrator implementation that registers these listeners.

In case when I CustomFlushListener implements three interfaces, how to register it properly?

I have other CustomUpdateEcentListener that implements PostUpdateEventListener and this is easy - I just register it as below, what about CustomFlushListener? Do I have to register it three times - once per each interface, how should it look like?


**Spring Bean:**

Code:
   public class CustomFlushListener implements FlushEventListener, FlushEntityEventListener, AutoFlushEventListener{
    ....
    }


**Integrator Bean:**

Code:
public class HbCustomIntegrator implements Integrator {
   
        private static final Logger LOG = Logger.getLogger(HbCustomIntegrator.class);
   
        PostUpdateEventListener postUpdateEventListener;
     
   
        @Override
        public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactoryImplementor, SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {
            final EventListenerRegistry eventRegistry = sessionFactoryServiceRegistry.getService(EventListenerRegistry.class);
   
            LOG.info("Registering event listeners");
   
            eventRegistry.appendListeners(POST_UPDATE, postUpdateEventListener);
            eventRegistry.appendListeners(FLUSH, ????);
            eventRegistry.appendListeners(FLUSH_ENTITY, ????);
           
   
        }

    @Override
    public void disintegrate(SessionFactoryImplementor sessionFactoryImplementor, SessionFactoryServiceRegistry sessionFactoryServiceRegistry) {

    }


Top
 Profile  
 
 Post subject: Re: Registering Hibernate 4 listeners, Integrator
PostPosted: Mon May 23, 2016 8:38 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can inject the CustomFlushListener in your HbCustomIntegrator and then simply feed the reference to all those three event types, just like in this SO answer.


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.