HHH-10264 - hibernate.cache.auto_evict_collection_cache problems;

HHH-9140 - Error in CollectionCacheInvalidator when hibernate.cache.auto_evict_collection_cache is enabled
This commit is contained in:
Steve Ebersole 2015-11-10 09:10:07 -06:00
parent bf2eb01856
commit 1d5b0779d6
3 changed files with 30 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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() {