Skip to content

Commit 60e8f8c

Browse files
committed
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 1d5b077)
1 parent 6dbb3a8 commit 60e8f8c

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/CollectionCacheInvalidator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
public class CollectionCacheInvalidator
4646
implements Integrator, PostInsertEventListener, PostDeleteEventListener, PostUpdateEventListener {
4747
private static final Logger LOG = Logger.getLogger( CollectionCacheInvalidator.class.getName() );
48-
public static final String PROPAGATE_EXCEPTION = "hibernate.test.auto_evict_collection_cache.propagate_exception";
49-
private boolean propagateException;
48+
49+
/**
50+
* Exposed for use in testing
51+
*/
52+
public static boolean PROPAGATE_EXCEPTION = false;
5053

5154
@Override
5255
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory,
@@ -87,8 +90,6 @@ private void integrate(SessionFactoryServiceRegistry serviceRegistry, SessionFac
8790
// Nothing to do, if caching is disabled
8891
return;
8992
}
90-
propagateException = Boolean.parseBoolean(
91-
sessionFactory.getProperties().getProperty( PROPAGATE_EXCEPTION ) );
9293
EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
9394
eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
9495
eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
@@ -149,7 +150,7 @@ public void doAfterTransactionCompletion(boolean success, SessionImplementor ses
149150
}
150151
}
151152
catch ( Exception e ) {
152-
if ( propagateException ) {
153+
if ( PROPAGATE_EXCEPTION ) {
153154
throw new IllegalStateException( e );
154155
}
155156
// don't let decaching influence other logic

hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import org.hibernate.testing.TestForIssue;
1919
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
20+
import org.junit.After;
21+
import org.junit.Before;
2022
import org.junit.Test;
2123

2224
import static org.junit.Assert.assertEquals;
@@ -34,14 +36,23 @@ protected Class<?>[] getAnnotatedClasses() {
3436
return new Class[] { User.class, Company.class };
3537
}
3638

39+
@Before
40+
public void before() {
41+
CollectionCacheInvalidator.PROPAGATE_EXCEPTION = true;
42+
}
43+
44+
@After
45+
public void after() {
46+
CollectionCacheInvalidator.PROPAGATE_EXCEPTION = false;
47+
}
48+
3749
@Override
3850
protected void configure(Configuration cfg) {
3951
super.configure( cfg );
4052
cfg.setProperty( Environment.AUTO_EVICT_COLLECTION_CACHE, "true" );
4153
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
4254
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
4355
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" );
44-
cfg.setProperty( CollectionCacheInvalidator.PROPAGATE_EXCEPTION, "true" );
4556
}
4657

4758
@Override

hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionWithoutMappedByTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import org.hibernate.cfg.Environment;
2525

2626
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
27+
import org.junit.After;
28+
import org.junit.Before;
2729
import org.junit.Test;
2830

2931
import static org.junit.Assert.assertEquals;
@@ -38,13 +40,22 @@ protected Class<?>[] getAnnotatedClasses() {
3840
return new Class[] {Person.class, People.class};
3941
}
4042

43+
@Before
44+
public void before() {
45+
CollectionCacheInvalidator.PROPAGATE_EXCEPTION = true;
46+
}
47+
48+
@After
49+
public void after() {
50+
CollectionCacheInvalidator.PROPAGATE_EXCEPTION = false;
51+
}
52+
4153
@Override
4254
protected void configure(Configuration cfg) {
4355
cfg.setProperty( Environment.AUTO_EVICT_COLLECTION_CACHE, "true" );
4456
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
4557
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
4658
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" );
47-
cfg.setProperty( CollectionCacheInvalidator.PROPAGATE_EXCEPTION, "true" );
4859
}
4960

5061
private People createPeople() {

0 commit comments

Comments
 (0)