diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java index 8dfc849ed5..20b94278bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/TwoPhaseLoad.java @@ -105,29 +105,6 @@ public final class TwoPhaseLoad { } } - /** - * @deprecated This method will be removed. Use {@link #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, Iterable)} instead. - * - * @param entity The entity being loaded - * @param readOnly Is the entity being loaded as read-only - * @param session The Session - * @param preLoadEvent The (re-used) pre-load event - */ - @Deprecated - public static void initializeEntity( - final Object entity, - final boolean readOnly, - final SharedSessionContractImplementor session, - final PreLoadEvent preLoadEvent) { - final EventListenerGroup listenerGroup = session - .getFactory() - .getServiceRegistry() - .getService( EventListenerRegistry.class ) - .getEventListenerGroup( EventType.PRE_LOAD ); - final Iterable listeners = listenerGroup.listeners(); - initializeEntity( entity, readOnly, session, preLoadEvent, listeners, EntityResolver.DEFAULT ); - } - /** * Perform the second step of 2-phase load. Fully initialize the entity * instance. @@ -140,15 +117,13 @@ public final class TwoPhaseLoad { * @param readOnly Is the entity being loaded as read-only * @param session The Session * @param preLoadEvent The (re-used) pre-load event - * @param preLoadEventListeners the pre-load event listeners */ public static void initializeEntity( final Object entity, final boolean readOnly, final SharedSessionContractImplementor session, - final PreLoadEvent preLoadEvent, - final Iterable preLoadEventListeners) { - initializeEntity( entity, readOnly, session, preLoadEvent, preLoadEventListeners, EntityResolver.DEFAULT ); + final PreLoadEvent preLoadEvent) { + initializeEntity( entity, readOnly, session, preLoadEvent, EntityResolver.DEFAULT ); } /** @@ -163,7 +138,6 @@ public final class TwoPhaseLoad { * @param readOnly Is the entity being loaded as read-only * @param session The Session * @param preLoadEvent The (re-used) pre-load event - * @param preLoadEventListeners the pre-load event listeners * @param entityResolver the resolver used for to-one entity associations * (not used when an entity is a bytecode-enhanced lazy entity) */ @@ -172,7 +146,6 @@ public final class TwoPhaseLoad { final boolean readOnly, final SharedSessionContractImplementor session, final PreLoadEvent preLoadEvent, - final Iterable preLoadEventListeners, final EntityResolver entityResolver) { final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityEntry entityEntry = persistenceContext.getEntry( entity ); @@ -180,7 +153,7 @@ public final class TwoPhaseLoad { throw new AssertionFailure( "possible non-threadsafe access to the session" ); } initializeEntityEntryLoadedState( entity, entityEntry, session, entityResolver ); - initializeEntityFromEntityEntryLoadedState( entity, entityEntry, readOnly, session, preLoadEvent, preLoadEventListeners ); + initializeEntityFromEntityEntryLoadedState( entity, entityEntry, readOnly, session, preLoadEvent ); } public static void initializeEntityEntryLoadedState( @@ -261,8 +234,7 @@ public final class TwoPhaseLoad { final EntityEntry entityEntry, final boolean readOnly, final SharedSessionContractImplementor session, - final PreLoadEvent preLoadEvent, - final Iterable preLoadEventListeners) throws HibernateException { + final PreLoadEvent preLoadEvent) throws HibernateException { final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final EntityPersister persister = entityEntry.getPersister(); @@ -274,9 +246,8 @@ public final class TwoPhaseLoad { //Must occur after resolving identifiers! if ( session.isEventSource() ) { preLoadEvent.setEntity( entity ).setState( hydratedState ).setId( id ).setPersister( persister ); - for ( PreLoadEventListener listener : preLoadEventListeners ) { - listener.onPreLoad( preLoadEvent ); - } + session.getFactory().getFastSessionServices() + .eventListenerGroup_PRE_LOAD.fireEventOnEachListener( preLoadEvent, PreLoadEventListener::onPreLoad ); } persister.setPropertyValues( entity, hydratedState ); @@ -589,7 +560,7 @@ public final class TwoPhaseLoad { /** * Implementations determine how a to-one associations is resolved. * - * @see #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, Iterable, EntityResolver) + * @see #initializeEntity(Object, boolean, SharedSessionContractImplementor, PreLoadEvent, EntityResolver) */ public interface EntityResolver { diff --git a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java index 2095ecc0f6..db8e0e2fbe 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -1184,14 +1184,8 @@ public abstract class Loader { LOG.tracev( "Total objects hydrated: {0}", hydratedObjectsSize ); if ( hydratedObjectsSize != 0 ) { - final Iterable listeners = session - .getFactory() - .getFastSessionServices() - .eventListenerGroup_PRE_LOAD - .listeners(); - for ( Object hydratedObject : hydratedObjects ) { - TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre, listeners ); + TwoPhaseLoad.initializeEntity( hydratedObject, readOnly, session, pre ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/AbstractRowReader.java b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/AbstractRowReader.java index 4e640e41e1..32f8b01870 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/AbstractRowReader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/plan/exec/process/internal/AbstractRowReader.java @@ -237,19 +237,13 @@ public abstract class AbstractRowReader implements RowReader { } final SharedSessionContractImplementor session = context.getSession(); - final Iterable listeners = session - .getFactory() - .getFastSessionServices() - .eventListenerGroup_PRE_LOAD - .listeners(); for ( HydratedEntityRegistration registration : hydratedEntityRegistrations ) { TwoPhaseLoad.initializeEntity( registration.getInstance(), context.isReadOnly(), session, - preLoadEvent, - listeners + preLoadEvent ); } }