From 60e8f8cfe4d2cbb7593dca5d3cc7ee131eeb4c7f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Tue, 10 Nov 2015 09:10:07 -0600 Subject: [PATCH] HHH-10264 - hibernate.cache.auto_evict_collection_cache problems; HHH-9140 - Error in CollectionCacheInvalidator when hibernate.cache.auto_evict_collection_cache is enabled (cherry picked from commit 1d5b0779d6df327f935e9be306ac203a84345ae0) --- .../cache/internal/CollectionCacheInvalidator.java | 11 ++++++----- .../test/cache/CollectionCacheEvictionTest.java | 13 ++++++++++++- .../CollectionCacheEvictionWithoutMappedByTest.java | 13 ++++++++++++- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java index fb1c51526c..060f59545a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java @@ -45,8 +45,11 @@ import org.jboss.logging.Logger; public class CollectionCacheInvalidator implements Integrator, PostInsertEventListener, PostDeleteEventListener, PostUpdateEventListener { private static final Logger LOG = Logger.getLogger( CollectionCacheInvalidator.class.getName() ); - public static final String PROPAGATE_EXCEPTION = "hibernate.test.auto_evict_collection_cache.propagate_exception"; - private boolean propagateException; + + /** + * Exposed for use in testing + */ + public static boolean PROPAGATE_EXCEPTION = false; @Override public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, @@ -87,8 +90,6 @@ public class CollectionCacheInvalidator // Nothing to do, if caching is disabled return; } - propagateException = Boolean.parseBoolean( - sessionFactory.getProperties().getProperty( PROPAGATE_EXCEPTION ) ); EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class ); eventListenerRegistry.appendListeners( EventType.POST_INSERT, this ); eventListenerRegistry.appendListeners( EventType.POST_DELETE, this ); @@ -149,7 +150,7 @@ public class CollectionCacheInvalidator } } catch ( Exception e ) { - if ( propagateException ) { + if ( PROPAGATE_EXCEPTION ) { throw new IllegalStateException( e ); } // don't let decaching influence other logic diff --git a/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java b/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java index 1ccce81d8e..9c559cf98c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java @@ -17,6 +17,8 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -34,6 +36,16 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase { return new Class[] { User.class, Company.class }; } + @Before + public void before() { + CollectionCacheInvalidator.PROPAGATE_EXCEPTION = true; + } + + @After + public void after() { + CollectionCacheInvalidator.PROPAGATE_EXCEPTION = false; + } + @Override protected void configure(Configuration cfg) { super.configure( cfg ); @@ -41,7 +53,6 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase { cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" ); cfg.setProperty( Environment.USE_QUERY_CACHE, "true" ); cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" ); - cfg.setProperty( CollectionCacheInvalidator.PROPAGATE_EXCEPTION, "true" ); } @Override diff --git a/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionWithoutMappedByTest.java b/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionWithoutMappedByTest.java index eaf3ac4be8..96822c7fc1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionWithoutMappedByTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionWithoutMappedByTest.java @@ -24,6 +24,8 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -38,13 +40,22 @@ public class CollectionCacheEvictionWithoutMappedByTest extends BaseCoreFunction return new Class[] {Person.class, People.class}; } + @Before + public void before() { + CollectionCacheInvalidator.PROPAGATE_EXCEPTION = true; + } + + @After + public void after() { + CollectionCacheInvalidator.PROPAGATE_EXCEPTION = false; + } + @Override protected void configure(Configuration cfg) { cfg.setProperty( Environment.AUTO_EVICT_COLLECTION_CACHE, "true" ); cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" ); cfg.setProperty( Environment.USE_QUERY_CACHE, "true" ); cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" ); - cfg.setProperty( CollectionCacheInvalidator.PROPAGATE_EXCEPTION, "true" ); } private People createPeople() {