HHH-12649 Use the 'create-warn' missing cache strategy by default in hibernate-jcache
In order to be consistent with hibernate-ehcache.
This commit is contained in:
parent
21eac287e9
commit
3883abf087
|
@ -563,9 +563,9 @@ Only by specifying the second property `hibernate.javax.cache.uri` will you be a
|
||||||
==== JCache missing cache strategy
|
==== JCache missing cache strategy
|
||||||
|
|
||||||
By default, the JCache region factory
|
By default, the JCache region factory
|
||||||
will throw an exception when asked to retrieve a cache that is not pre-configured and pre-started in the underlying cache manager.
|
will log a warning when asked to create a cache that is not explicitly configured and pre-started in the underlying cache manager.
|
||||||
Thus if you configure an entity type or a collection as cached, but do not configure the corresponding cache explicitly,
|
Thus if you configure an entity type or a collection as cached, but do not configure the corresponding cache explicitly,
|
||||||
Hibernate ORM will fail to start.
|
one warning will be logged for each cache that was not configured explicitly.
|
||||||
|
|
||||||
You may change this behavior by setting the `hibernate.javax.cache.missing_cache_strategy` property
|
You may change this behavior by setting the `hibernate.javax.cache.missing_cache_strategy` property
|
||||||
to one of the following values:
|
to one of the following values:
|
||||||
|
@ -574,8 +574,8 @@ to one of the following values:
|
||||||
[cols=",",options="header",]
|
[cols=",",options="header",]
|
||||||
|======================================
|
|======================================
|
||||||
| Value | Description
|
| Value | Description
|
||||||
|`fail` | **Default value**. Fail with an exception on missing caches.
|
|`fail` | Fail with an exception on missing caches.
|
||||||
|`create-warn` | Create a new cache when a cache is not found (see `create` below),
|
|`create-warn` | **Default value**. Create a new cache when a cache is not found (see `create` below),
|
||||||
and also log a warning about the missing cache.
|
and also log a warning about the missing cache.
|
||||||
|`create` | Create a new cache when a cache is not found, without logging any warning about the missing cache.
|
|`create` | Create a new cache when a cache is not found, without logging any warning about the missing cache.
|
||||||
|======================================
|
|======================================
|
||||||
|
|
|
@ -52,7 +52,7 @@ public enum MissingCacheStrategy {
|
||||||
|
|
||||||
if ( StringHelper.isEmpty( externalRepresentation ) ) {
|
if ( StringHelper.isEmpty( externalRepresentation ) ) {
|
||||||
// Use the default
|
// Use the default
|
||||||
return MissingCacheStrategy.FAIL;
|
return MissingCacheStrategy.CREATE_WARN;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( MissingCacheStrategy strategy : values() ) {
|
for ( MissingCacheStrategy strategy : values() ) {
|
||||||
|
|
|
@ -45,26 +45,22 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingCacheStrategyDefault() {
|
public void testMissingCacheStrategyDefault() {
|
||||||
doTestMissingCacheStrategyFail(
|
doTestMissingCacheStrategyCreateWarn(
|
||||||
ignored -> { } // default settings
|
ignored -> { } // default settings
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingCacheStrategyFail() {
|
public void testMissingCacheStrategyFail() {
|
||||||
doTestMissingCacheStrategyFail(
|
|
||||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "fail" )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTestMissingCacheStrategyFail(Consumer<StandardServiceRegistryBuilder> additionalSettings) {
|
|
||||||
// first, lets make sure that the region names we think are non-existent really do not exist
|
// first, lets make sure that the region names we think are non-existent really do not exist
|
||||||
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
||||||
assertThat( TestHelper.getCache( regionName ), nullValue() );
|
assertThat( TestHelper.getCache( regionName ), nullValue() );
|
||||||
}
|
}
|
||||||
|
|
||||||
// and now let's try to build the standard testing SessionFactory, without pre-defining caches
|
// and now 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();
|
fail();
|
||||||
}
|
}
|
||||||
catch (ServiceException expected) {
|
catch (ServiceException expected) {
|
||||||
|
@ -98,6 +94,12 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMissingCacheStrategyCreateWarn() {
|
public void testMissingCacheStrategyCreateWarn() {
|
||||||
|
doTestMissingCacheStrategyCreateWarn(
|
||||||
|
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTestMissingCacheStrategyCreateWarn(Consumer<StandardServiceRegistryBuilder> additionalSettings) {
|
||||||
Map<String, Triggerable> triggerables = new HashMap<>();
|
Map<String, Triggerable> triggerables = new HashMap<>();
|
||||||
|
|
||||||
// first, lets make sure that the region names we think are non-existent really do not exist
|
// first, lets make sure that the region names we think are non-existent really do not exist
|
||||||
|
@ -111,9 +113,7 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory(
|
try ( SessionFactoryImplementor ignored = TestHelper.buildStandardSessionFactory( additionalSettings ) ) {
|
||||||
builder -> builder.applySetting( ConfigSettings.MISSING_CACHE_STRATEGY, "create-warn" )
|
|
||||||
) ) {
|
|
||||||
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
for ( String regionName : TestHelper.allDomainRegionNames ) {
|
||||||
// The caches should have been created automatically
|
// The caches should have been created automatically
|
||||||
assertThat(
|
assertThat(
|
||||||
|
|
Loading…
Reference in New Issue