From 75c2a6d619702ab47c0f221edee75488244b47a2 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 25 Apr 2018 12:18:28 -0700 Subject: [PATCH] HHH-12508 : SessionFactoryOptions#isSecondLevelCacheEnabled returns true by default with NoCachingRegionFactory --- .../internal/SessionFactoryBuilderImpl.java | 56 ++++++++++++------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java index 06512e8576..7a05b22437 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java @@ -37,6 +37,7 @@ import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.spi.MetadataImplementor; import org.hibernate.boot.spi.SessionFactoryBuilderImplementor; import org.hibernate.boot.spi.SessionFactoryOptions; +import org.hibernate.cache.internal.NoCachingRegionFactory; import org.hibernate.cache.internal.StandardQueryCacheFactory; import org.hibernate.cache.spi.QueryCacheFactory; import org.hibernate.cache.spi.RegionFactory; @@ -684,25 +685,42 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement this.procedureParameterNullPassingEnabled = cfgService.getSetting( PROCEDURE_NULL_PARAM_PASSING, BOOLEAN, false ); this.collectionJoinSubqueryRewriteEnabled = cfgService.getSetting( COLLECTION_JOIN_SUBQUERY, BOOLEAN, true ); - this.secondLevelCacheEnabled = cfgService.getSetting( USE_SECOND_LEVEL_CACHE, BOOLEAN, true ); - this.queryCacheEnabled = cfgService.getSetting( USE_QUERY_CACHE, BOOLEAN, false ); - this.queryCacheFactory = strategySelector.resolveDefaultableStrategy( - QueryCacheFactory.class, - configurationSettings.get( QUERY_CACHE_FACTORY ), - StandardQueryCacheFactory.INSTANCE - ); - this.cacheRegionPrefix = ConfigurationHelper.extractPropertyValue( - CACHE_REGION_PREFIX, - configurationSettings - ); - this.minimalPutsEnabled = cfgService.getSetting( - USE_MINIMAL_PUTS, - BOOLEAN, - serviceRegistry.getService( RegionFactory.class ).isMinimalPutsEnabledByDefault() - ); - this.structuredCacheEntriesEnabled = cfgService.getSetting( USE_STRUCTURED_CACHE, BOOLEAN, false ); - this.directReferenceCacheEntriesEnabled = cfgService.getSetting( USE_DIRECT_REFERENCE_CACHE_ENTRIES,BOOLEAN, false ); - this.autoEvictCollectionCache = cfgService.getSetting( AUTO_EVICT_COLLECTION_CACHE, BOOLEAN, false ); + final RegionFactory regionFactory = serviceRegistry.getService( RegionFactory.class ); + if ( !NoCachingRegionFactory.class.isInstance( regionFactory ) ) { + this.secondLevelCacheEnabled = cfgService.getSetting( USE_SECOND_LEVEL_CACHE, BOOLEAN, true ); + this.queryCacheEnabled = cfgService.getSetting( USE_QUERY_CACHE, BOOLEAN, false ); + this.queryCacheFactory = strategySelector.resolveDefaultableStrategy( + QueryCacheFactory.class, + configurationSettings.get( QUERY_CACHE_FACTORY ), + StandardQueryCacheFactory.INSTANCE + ); + this.cacheRegionPrefix = ConfigurationHelper.extractPropertyValue( + CACHE_REGION_PREFIX, + configurationSettings + ); + this.minimalPutsEnabled = cfgService.getSetting( + USE_MINIMAL_PUTS, + BOOLEAN, + regionFactory.isMinimalPutsEnabledByDefault() + ); + this.structuredCacheEntriesEnabled = cfgService.getSetting( USE_STRUCTURED_CACHE, BOOLEAN, false ); + this.directReferenceCacheEntriesEnabled = cfgService.getSetting( + USE_DIRECT_REFERENCE_CACHE_ENTRIES, + BOOLEAN, + false + ); + this.autoEvictCollectionCache = cfgService.getSetting( AUTO_EVICT_COLLECTION_CACHE, BOOLEAN, false ); + } + else { + this.secondLevelCacheEnabled = false; + this.queryCacheEnabled = false; + this.queryCacheFactory = null; + this.cacheRegionPrefix = null; + this.minimalPutsEnabled = false; + this.structuredCacheEntriesEnabled = false; + this.directReferenceCacheEntriesEnabled = false; + this.autoEvictCollectionCache = false; + } try { this.schemaAutoTooling = SchemaAutoTooling.interpret( (String) configurationSettings.get( AvailableSettings.HBM2DDL_AUTO ) );