diff --git a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/EhcacheRegionFactory.java b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/EhcacheRegionFactory.java index e5cea1a9f1..650ee27258 100644 --- a/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/EhcacheRegionFactory.java +++ b/hibernate-ehcache/src/main/java/org/hibernate/cache/ehcache/internal/EhcacheRegionFactory.java @@ -283,7 +283,9 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate { * Load a resource from the classpath. */ protected URL loadResource(String configurationResourceName) { - if ( ! isStarted() ) { + // we use this method to create the cache manager so we can't check it is non null + // calling the super method then + if ( ! super.isStarted() ) { throw new IllegalStateException( "Cannot load resource through a non-started EhcacheRegionFactory" ); } diff --git a/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/SingletonEhCacheRegionFactoryClasspathConfigurationFileTest.java b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/SingletonEhCacheRegionFactoryClasspathConfigurationFileTest.java new file mode 100644 index 0000000000..1b353ec496 --- /dev/null +++ b/hibernate-ehcache/src/test/java/org/hibernate/cache/ehcache/test/SingletonEhCacheRegionFactoryClasspathConfigurationFileTest.java @@ -0,0 +1,35 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.cache.ehcache.test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertNotNull; + +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cache.ehcache.ConfigSettings; +import org.hibernate.cache.ehcache.internal.SingletonEhcacheRegionFactory; +import org.hibernate.cache.spi.RegionFactory; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.testing.TestForIssue; +import org.junit.Test; + +@TestForIssue(jiraKey = "HHH-12869") +public class SingletonEhCacheRegionFactoryClasspathConfigurationFileTest { + + @Test + public void testCacheInitialization() { + try ( SessionFactoryImplementor sessionFactory = TestHelper.buildStandardSessionFactory( + builder -> builder.applySetting( AvailableSettings.CACHE_REGION_FACTORY, "ehcache-singleton" ) + .applySetting( ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME, + "/hibernate-config/ehcache-configuration.xml" ) ) ) { + assertNotNull( sessionFactory ); + } + } +} diff --git a/hibernate-ehcache/src/test/resources/hibernate-config/ehcache-configuration.xml b/hibernate-ehcache/src/test/resources/hibernate-config/ehcache-configuration.xml new file mode 100644 index 0000000000..f67d705302 --- /dev/null +++ b/hibernate-ehcache/src/test/resources/hibernate-config/ehcache-configuration.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + +