HHH-15787 DefaultMergeEventlistener#onMerge is performing runtime services lookup

This commit is contained in:
Sanne Grinovero 2022-12-01 22:09:40 +00:00 committed by Sanne Grinovero
parent 329ccaa7a1
commit ed26c3f8fa
2 changed files with 11 additions and 8 deletions

View File

@ -28,7 +28,6 @@ import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.event.spi.EntityCopyObserver;
import org.hibernate.event.spi.EntityCopyObserverFactory;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.MergeContext;
import org.hibernate.event.spi.MergeEvent;
@ -75,11 +74,12 @@ public class DefaultMergeEventListener
*
*/
public void onMerge(MergeEvent event) throws HibernateException {
final EntityCopyObserver entityCopyObserver = createEntityCopyObserver( event.getSession().getFactory() );
final MergeContext mergeContext = new MergeContext( event.getSession(), entityCopyObserver );
final EventSource session = event.getSession();
final EntityCopyObserver entityCopyObserver = createEntityCopyObserver( session );
final MergeContext mergeContext = new MergeContext( session, entityCopyObserver );
try {
onMerge( event, mergeContext );
entityCopyObserver.topLevelMergeComplete( event.getSession() );
entityCopyObserver.topLevelMergeComplete( session );
}
finally {
entityCopyObserver.clear();
@ -87,10 +87,8 @@ public class DefaultMergeEventListener
}
}
private EntityCopyObserver createEntityCopyObserver(SessionFactoryImplementor sessionFactory) {
return sessionFactory.getServiceRegistry()
.getService( EntityCopyObserverFactory.class )
.createEntityCopyObserver();
private EntityCopyObserver createEntityCopyObserver(final EventSource session) {
return session.getFactory().getFastSessionServices().entityCopyObserverFactory.createEntityCopyObserver();
}
/**

View File

@ -33,6 +33,7 @@ import org.hibernate.event.spi.AutoFlushEventListener;
import org.hibernate.event.spi.ClearEventListener;
import org.hibernate.event.spi.DeleteEventListener;
import org.hibernate.event.spi.DirtyCheckEventListener;
import org.hibernate.event.spi.EntityCopyObserverFactory;
import org.hibernate.event.spi.EventType;
import org.hibernate.event.spi.EvictEventListener;
import org.hibernate.event.spi.FlushEntityEventListener;
@ -164,6 +165,9 @@ public final class FastSessionServices {
final LockOptions defaultLockOptions;
final int defaultJdbcBatchSize;
//This one needs to be public unfortunately:
public final EntityCopyObserverFactory entityCopyObserverFactory;
//Private fields:
private final Dialect dialect;
private final CacheStoreMode defaultCacheStoreMode;
@ -232,6 +236,7 @@ public final class FastSessionServices {
this.classLoaderService = sr.getService( ClassLoaderService.class );
this.transactionCoordinatorBuilder = sr.getService( TransactionCoordinatorBuilder.class );
this.jdbcServices = sr.getService( JdbcServices.class );
this.entityCopyObserverFactory = sr.getService( EntityCopyObserverFactory.class );
this.isJtaTransactionAccessible = isTransactionAccessible( sf, transactionCoordinatorBuilder );