private void injectEventListeners(final ServiceRegistry registry) {

        EventListenerRegistry eventRegistry = registry
                .getService(EventListenerRegistry.class);

        List<PostInsertEventListener> postInsertEvents = locator
                .getAllServices(PostInsertEventListener.class);
        for (PostInsertEventListener piEventListener : postInsertEvents) {
            logger.trace("Registering PostInsert: " + piEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_INSERT,
                    piEventListener);
        }

        List<PostUpdateEventListener> postUpdateEvents = locator
                .getAllServices(PostUpdateEventListener.class);
        for (PostUpdateEventListener puEventListener : postUpdateEvents) {
            logger.trace("Registering PostUpdate: " + puEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_UPDATE,
                    puEventListener);
        }

        List<PostDeleteEventListener> postDeleteEvents = locator
                .getAllServices(PostDeleteEventListener.class);
        for (PostDeleteEventListener pdEventListener : postDeleteEvents) {
            logger.trace("Registering PostDelete: " + pdEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_DELETE,
                    pdEventListener);
        }

        List<PreInsertEventListener> preInsertEvents = locator
                .getAllServices(PreInsertEventListener.class);
        for (PreInsertEventListener piEventListener : preInsertEvents) {
            logger.trace("Registering PreInsert: " + piEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.PRE_INSERT,
                    piEventListener);
        }

        List<PreUpdateEventListener> preUpdateEvents = locator
                .getAllServices(PreUpdateEventListener.class);
        for (PreUpdateEventListener puEventListener : preUpdateEvents) {
            logger.trace("Registering PreUpdate: " + puEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.PRE_UPDATE,
                    puEventListener);
        }

        List<PreDeleteEventListener> preDeleteEvents = locator
                .getAllServices(PreDeleteEventListener.class);
        for (PreDeleteEventListener pdEventListener : preDeleteEvents) {
            logger.trace("Registering PreDelete: " + pdEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.PRE_DELETE,
                    pdEventListener);
        }

        List<PostCommitInsertEventListener> pciEvents = locator
                .getAllServices(PostCommitInsertEventListener.class);
        for (PostCommitInsertEventListener cpiEventListener : pciEvents) {
            logger.trace("Registering PostCommitInsert: " + cpiEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_COMMIT_INSERT,
                    cpiEventListener);
        }

        List<PostCommitUpdateEventListener> pcuEvents = locator
                .getAllServices(PostCommitUpdateEventListener.class);
        for (PostCommitUpdateEventListener cpuEventListener : pcuEvents) {
            logger.trace("Registering PostCommitUpdate: " + cpuEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_COMMIT_UPDATE,
                    cpuEventListener);
        }

        List<PostCommitDeleteEventListener> pcdEvents = locator
                .getAllServices(PostCommitDeleteEventListener.class);
        for (PostCommitDeleteEventListener cpdEventListener : pcdEvents) {
            logger.trace("Registering PostCommitDelete: " + cpdEventListener
                    .getClass().getCanonicalName());
            eventRegistry.appendListeners(EventType.POST_COMMIT_DELETE,
                    cpdEventListener);
        }
    }
private void injectEventListeners ( final ServiceRegistry registry ) { EventListenerRegistry eventRegistry = registry . getService ( EventListenerRegistry . class ) ; List < PostInsertEventListener > postInsertEvents = locator . getAllServices ( PostInsertEventListener . class ) ; for ( PostInsertEventListener piEventListener : postInsertEvents ) { logger . trace ( "Registering PostInsert: " + piEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_INSERT , piEventListener ) ; } List < PostUpdateEventListener > postUpdateEvents = locator . getAllServices ( PostUpdateEventListener . class ) ; for ( PostUpdateEventListener puEventListener : postUpdateEvents ) { logger . trace ( "Registering PostUpdate: " + puEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_UPDATE , puEventListener ) ; } List < PostDeleteEventListener > postDeleteEvents = locator . getAllServices ( PostDeleteEventListener . class ) ; for ( PostDeleteEventListener pdEventListener : postDeleteEvents ) { logger . trace ( "Registering PostDelete: " + pdEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_DELETE , pdEventListener ) ; } List < PreInsertEventListener > preInsertEvents = locator . getAllServices ( PreInsertEventListener . class ) ; for ( PreInsertEventListener piEventListener : preInsertEvents ) { logger . trace ( "Registering PreInsert: " + piEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . PRE_INSERT , piEventListener ) ; } List < PreUpdateEventListener > preUpdateEvents = locator . getAllServices ( PreUpdateEventListener . class ) ; for ( PreUpdateEventListener puEventListener : preUpdateEvents ) { logger . trace ( "Registering PreUpdate: " + puEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . PRE_UPDATE , puEventListener ) ; } List < PreDeleteEventListener > preDeleteEvents = locator . getAllServices ( PreDeleteEventListener . class ) ; for ( PreDeleteEventListener pdEventListener : preDeleteEvents ) { logger . trace ( "Registering PreDelete: " + pdEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . PRE_DELETE , pdEventListener ) ; } List < PostCommitInsertEventListener > pciEvents = locator . getAllServices ( PostCommitInsertEventListener . class ) ; for ( PostCommitInsertEventListener cpiEventListener : pciEvents ) { logger . trace ( "Registering PostCommitInsert: " + cpiEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_COMMIT_INSERT , cpiEventListener ) ; } List < PostCommitUpdateEventListener > pcuEvents = locator . getAllServices ( PostCommitUpdateEventListener . class ) ; for ( PostCommitUpdateEventListener cpuEventListener : pcuEvents ) { logger . trace ( "Registering PostCommitUpdate: " + cpuEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_COMMIT_UPDATE , cpuEventListener ) ; } List < PostCommitDeleteEventListener > pcdEvents = locator . getAllServices ( PostCommitDeleteEventListener . class ) ; for ( PostCommitDeleteEventListener cpdEventListener : pcdEvents ) { logger . trace ( "Registering PostCommitDelete: " + cpdEventListener . getClass ( ) . getCanonicalName ( ) ) ; eventRegistry . appendListeners ( EventType . POST_COMMIT_DELETE , cpdEventListener ) ; } }
This method automatically adds discovered hibernate event listeners into
the hibernate service registry.

@param registry The service registry.