How to add service for a Custom EventListenerRegistryImpl

Hi everyone,

I have some problems when initiating the EventListenerRegistry in my application. I have created a custom EventListenerRegistry, called AutofetchEventListenerRegistryImpl. This is how I try to initialize my EventListenerRegistry:

eventListenerRegistry = ((SessionFactoryImpl) sessionFactory).getServiceRegistry()

This throws a UnknownServiceException.

My custom EventListenerRegistry looks like this:

public class AutofetchEventListenerRegistryImpl extends EventListenerRegistryImpl {

	private ExtentManager em;
	public AutofetchEventListenerRegistryImpl(ExtentManager em) {
		this.em = em;
	public <T> void setListeners(EventType<T> type, T... listeners) {
		setExtentManager(listeners, em);
		super.setListeners(type, listeners);
	private <T> void setExtentManager(T[] listeners, ExtentManager em) {
		for (Object listener : listeners) {
			if (listener instanceof AutofetchInitializeCollectionListener) {
				((AutofetchInitializeCollectionListener) listener).setExtentManager(em);
			if (listener instanceof AutofetchLoadListener) {
				((AutofetchLoadListener) listener).setExtentManager(em);

Is there something I need add in order for Hibernate to know what service my EventListenerRegistry is associated with?

Thanks and have a nice weekend.

Check out the Integration Guide which explains how to add Services to Hibernate.