From 7eccda9f36140dbda58970e8114c0c2317a764b8 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 4 Oct 2021 21:04:51 +0200 Subject: [PATCH] Fix java.lang.ClassCastException: org.hibernate.internal.StatelessSessionImpl cannot be cast to org.hibernate.event.spi.EventSource --- .../org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java | 1 + .../org/hibernate/loader/entity/CacheEntityLoaderHelper.java | 4 ++-- .../graph/entity/internal/EntityDelayedFetchInitializer.java | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java index a99fe5a4db..bb3c14045d 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/entry/StandardCacheEntryImpl.java @@ -11,6 +11,7 @@ import java.io.Serializable; import org.hibernate.AssertionFailure; import org.hibernate.HibernateException; import org.hibernate.Interceptor; +import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.service.spi.EventListenerGroup; import org.hibernate.event.service.spi.EventListenerRegistry; diff --git a/hibernate-core/src/main/java/org/hibernate/loader/entity/CacheEntityLoaderHelper.java b/hibernate-core/src/main/java/org/hibernate/loader/entity/CacheEntityLoaderHelper.java index 1c77ddd452..cd4c5933dd 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/entity/CacheEntityLoaderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/entity/CacheEntityLoaderHelper.java @@ -301,7 +301,7 @@ public class CacheEntityLoaderHelper { private Object convertCacheReferenceEntryToEntity( ReferenceCacheEntryImpl referenceCacheEntry, - EventSource session, + SharedSessionContractImplementor session, EntityKey entityKey) { final Object entity = referenceCacheEntry.getReference(); @@ -317,7 +317,7 @@ public class CacheEntityLoaderHelper { private void makeEntityCircularReferenceSafe( ReferenceCacheEntryImpl referenceCacheEntry, - EventSource session, + SharedSessionContractImplementor session, Object entity, EntityKey entityKey) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java index c2c8753c34..78e7add4dc 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/entity/internal/EntityDelayedFetchInitializer.java @@ -12,6 +12,8 @@ import org.hibernate.LockMode; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.PersistenceContext; +import org.hibernate.engine.spi.SessionImplementor; +import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.event.spi.EventSource; import org.hibernate.internal.log.LoggingHelper; import org.hibernate.loader.entity.CacheEntityLoaderHelper; @@ -104,7 +106,7 @@ public class EntityDelayedFetchInitializer extends AbstractFetchParentAccess imp final Object cachedEntity; if ( concreteDescriptor.getEntityMetamodel().hasSubclasses() ) { cachedEntity = CacheEntityLoaderHelper.INSTANCE.loadFromSecondLevelCache( - (EventSource) rowProcessingState.getSession(), + (SharedSessionContractImplementor) rowProcessingState.getSession(), null, LockMode.NONE, concreteDescriptor,