diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/MissingCacheStrategy.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/MissingCacheStrategy.java index b9868e8915..004ca8382d 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/MissingCacheStrategy.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/MissingCacheStrategy.java @@ -45,7 +45,8 @@ public static MissingCacheStrategy interpretSetting(Object value) { if ( StringHelper.isEmpty( externalRepresentation ) ) { // Use the default - return MissingCacheStrategy.FAIL; + // Default is CREATE_WARN for backward compatibility reasons; we should switch to FAIL at some point. + return MissingCacheStrategy.CREATE_WARN; } for ( MissingCacheStrategy strategy : values() ) { diff --git a/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/MissingCacheStrategyTest.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/MissingCacheStrategyTest.java index fcb940c467..fb4d13dad7 100644 --- a/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/MissingCacheStrategyTest.java +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/MissingCacheStrategyTest.java @@ -38,26 +38,22 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase { @Test public void testMissingCacheStrategyDefault() { - doTestMissingCacheStrategyFail( + doTestMissingCacheStrategyCreateWarn( ignored -> { } // default settings ); } @Test public void testMissingCacheStrategyFail() { - doTestMissingCacheStrategyFail( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) - ); - } - - private void doTestMissingCacheStrategyFail(Consumer additionalSettings) { /* * The cache manager is created per session factory, and we don't use any specific ehcache configuration, * so we know the caches don't exist before we start the session factory. */ // let's try to build the standard testing SessionFactory, without pre-defining caches - try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( additionalSettings ) ) { + try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( + builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" ) + ) ) { fail(); } catch (ServiceException expected) { @@ -91,6 +87,12 @@ public void testMissingCacheStrategyCreate() { @Test public void testMissingCacheStrategyCreateWarn() { + doTestMissingCacheStrategyCreateWarn( + builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" ) + ); + } + + private void doTestMissingCacheStrategyCreateWarn(Consumer additionalSettings) { /* * The cache manager is created per session factory, and we don't use any specific ehcache configuration, * so we know the caches don't exist before we start the session factory. @@ -106,9 +108,7 @@ public void testMissingCacheStrategyCreateWarn() { ); } - try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory( - builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" ) - ) ) { + try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory( additionalSettings ) ) { for ( String regionName : TestHelper.allRegionNames ) { // The caches should have been created automatically assertThat(