diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java index 570620d998..4c3eb5653b 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/impl/BaseTransactionalDataRegion.java @@ -17,11 +17,7 @@ import org.hibernate.cache.infinispan.access.TombstoneCallInterceptor; import org.hibernate.cache.infinispan.access.TxInvalidationCacheAccessDelegate; import org.hibernate.cache.infinispan.access.UnorderedDistributionInterceptor; import org.hibernate.cache.infinispan.access.VersionedCallInterceptor; -import org.hibernate.cache.infinispan.util.Caches; -import org.hibernate.cache.infinispan.util.FutureUpdate; -import org.hibernate.cache.infinispan.util.InfinispanMessageLogger; -import org.hibernate.cache.infinispan.util.Tombstone; -import org.hibernate.cache.infinispan.util.VersionedEntry; +import org.hibernate.cache.infinispan.util.*; import org.hibernate.cache.spi.CacheDataDescription; import org.hibernate.cache.spi.CacheKeysFactory; import org.hibernate.cache.spi.TransactionalDataRegion; @@ -148,8 +144,16 @@ public abstract class BaseTransactionalDataRegion assert strategy == Strategy.VALIDATION; return; } - validator = new PutFromLoadValidator(cache, factory); - strategy = Strategy.VALIDATION; + synchronized (this) { + PutFromLoadValidator found = findValidator(cache); + validator = found != null ? found : new PutFromLoadValidator(cache, factory); + strategy = Strategy.VALIDATION; + } + } + + private PutFromLoadValidator findValidator(AdvancedCache cache) { + CacheCommandInitializer cmdInit = cache.getComponentRegistry().getComponent(CacheCommandInitializer.class); + return cmdInit.findPutFromLoadValidator(cache.getName()); } protected void prepareForVersionedEntries() { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java index a1fd0d218d..9a8e361ed7 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheCommandInitializer.java @@ -48,6 +48,10 @@ public class CacheCommandInitializer implements ModuleCommandInitializer { putFromLoadValidators.put(cacheName, putFromLoadValidator); } + public PutFromLoadValidator findPutFromLoadValidator(String cacheName) { + return putFromLoadValidators.get(cacheName); + } + public PutFromLoadValidator removePutFromLoadValidator(String cacheName) { return putFromLoadValidators.remove(cacheName); }