diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CacheEntityLoaderHelper.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CacheEntityLoaderHelper.java index ba21a6ee9b..1d28683df1 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CacheEntityLoaderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/CacheEntityLoaderHelper.java @@ -317,12 +317,11 @@ public class CacheEntityLoaderHelper { Object entity = convertCacheEntryToEntity( entry, entityKey.getIdentifier(), source, persister, instanceToLoad, entityKey ); if ( !persister.isInstance( entity ) ) { + // Cleanup the inconsistent return class entity from the persistence context + final PersistenceContext persistenceContext = source.getPersistenceContext(); + persistenceContext.removeEntry( entity ); + persistenceContext.removeEntity( entityKey ); return null; -// throw new WrongClassException( -// "loaded object was of wrong class " + entity.getClass(), -// entityKey.getIdentifier(), -// persister.getEntityName() -// ); } return entity;