diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java index a91184dff2..171c083767 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/BatchFetchQueue.java @@ -218,7 +218,7 @@ public class BatchFetchQueue { } private boolean isCached(EntityKey entityKey, EntityPersister persister) { - if ( persister.hasCache() ) { + if ( context.getSession().getCacheMode().isGetEnabled() && persister.hasCache() ) { final CacheKey key = context.getSession().generateCacheKey( entityKey.getIdentifier(), persister.getIdentifierType(), @@ -331,7 +331,7 @@ public class BatchFetchQueue { } private boolean isCached(Serializable collectionKey, CollectionPersister persister) { - if ( persister.hasCache() ) { + if ( context.getSession().getCacheMode().isGetEnabled() && persister.hasCache() ) { CacheKey cacheKey = context.getSession().generateCacheKey( collectionKey, persister.getKeyType(), 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 5a2642fb51..031509a7c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/Loader.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/Loader.java @@ -1592,7 +1592,7 @@ public abstract class Loader { ); // see if the entity defines reference caching, and if so use the cached reference (if one). - if ( persister.canUseReferenceCacheEntries() ) { + if ( session.getCacheMode().isGetEnabled() && persister.canUseReferenceCacheEntries() ) { final Object cachedEntry = CacheHelper.fromSharedCache( session, session.generateCacheKey( diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 3d5b402370..642b1f1398 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -1004,7 +1004,7 @@ public abstract class AbstractEntityPersister LOG.tracev( "Initializing lazy properties of: {0}, field access: {1}", MessageHelper.infoString( this, id, getFactory() ), fieldName ); } - if ( hasCache() ) { + if ( session.getCacheMode().isGetEnabled() && hasCache() ) { final CacheKey cacheKey = session.generateCacheKey( id, getIdentifierType(), getEntityName() ); final Object ce = CacheHelper.fromSharedCache( session, cacheKey, getCacheAccessStrategy() ); if ( ce != null ) { @@ -4342,7 +4342,7 @@ public abstract class AbstractEntityPersister } // check to see if it is in the second-level cache - if ( hasCache() ) { + if ( session.getCacheMode().isGetEnabled() && hasCache() ) { final CacheKey ck = session.generateCacheKey( id, getIdentifierType(), getRootEntityName() ); final Object ce = CacheHelper.fromSharedCache( session, ck, getCacheAccessStrategy() ); if ( ce != null ) {