Skip to content

Commit

Permalink
HHH-9231 Avoid updating collection 2LC if contains entity added in tx
Browse files Browse the repository at this point in the history
(cherry picked from commit 3b098a94d3463086a230d6dbc1254e9ecbf76cda)

Conflicts:
	hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java

(cherry picked from commit 36e3520)
  • Loading branch information
galderz authored and gbadner committed Jul 9, 2014
1 parent 7ae53f6 commit 0b05168
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 19 deletions.
Expand Up @@ -44,6 +44,8 @@
import org.hibernate.engine.spi.Status;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.jboss.logging.Logger;

Expand Down Expand Up @@ -334,22 +336,34 @@ private void addCollectionToCache(LoadingCollectionEntry lce, CollectionPersiste
final CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister );
final CacheKey cacheKey = session.generateCacheKey( lce.getKey(), persister.getKeyType(), persister.getRole() );

try {
session.getEventListenerManager().cachePutStart();
final boolean put = persister.getCacheAccessStrategy().putFromLoad(
cacheKey,
persister.getCacheEntryStructure().structure( entry ),
session.getTimestamp(),
version,
factory.getSettings().isMinimalPutsEnabled() && session.getCacheMode()!= CacheMode.REFRESH
);

if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
boolean isPutFromLoad = true;
for (Serializable id : entry.getState()) {
EntityPersister entityPersister = ((QueryableCollection) persister).getElementPersister();
if ( session.getPersistenceContext().wasInsertedDuringTransaction( entityPersister, id ) ) {
isPutFromLoad = false;
break;
}
}
finally {
session.getEventListenerManager().cachePutEnd();

// CollectionRegionAccessStrategy has no update, so avoid putting uncommitted data via putFromLoad
if (isPutFromLoad) {
try {
session.getEventListenerManager().cachePutStart();
final boolean put = persister.getCacheAccessStrategy().putFromLoad(
cacheKey,
persister.getCacheEntryStructure().structure( entry ),
session.getTimestamp(),
version,
factory.getSettings().isMinimalPutsEnabled() && session.getCacheMode()!= CacheMode.REFRESH
);

if ( put && factory.getStatistics().isStatisticsEnabled() ) {
factory.getStatisticsImplementor().secondLevelCachePut( persister.getCacheAccessStrategy().getRegion().getName() );
}
}
finally {
session.getEventListenerManager().cachePutEnd();
}
}
}

Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.hibernate.cache.infinispan.access.PutFromLoadValidator;
import org.hibernate.criterion.Restrictions;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

import org.hibernate.Session;
Expand All @@ -44,7 +43,6 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.stat.SecondLevelCacheStatistics;
import org.hibernate.stat.Statistics;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;

import static junit.framework.Assert.assertNotNull;
Expand Down Expand Up @@ -146,7 +144,7 @@ public Void call() throws Exception {
}

@Test
@TestForIssue( jiraKey = "HHH-9231")
@TestForIssue( jiraKey = "HHH-9231" )
public void testAddNewOneToManyElementInitFlushLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
Expand Down Expand Up @@ -227,7 +225,7 @@ public void testAddNewOneToManyElementInitFlushLeaveCacheConsistent() throws Exc
}

@Test
@TestForIssue( jiraKey = "HHH-9231")
@TestForIssue( jiraKey = "HHH-9231" )
public void testAddNewOneToManyElementNoInitFlushLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
Expand Down Expand Up @@ -308,7 +306,6 @@ public void testAddNewOneToManyElementNoInitFlushLeaveCacheConsistent() throws E
}

@Test
@FailureExpected( jiraKey = "HHH-9231")
public void testAddNewOneToManyElementNoInitFlushInitLeaveCacheConsistent() throws Exception {
Statistics stats = sessionFactory().getStatistics();
stats.clear();
Expand Down

0 comments on commit 0b05168

Please sign in to comment.