HHH-9231 Avoid updating collection 2LC if contains entity added in tx
(cherry picked from commit 3b098a94d3463086a230d6dbc1254e9ecbf76cda) Conflicts: hibernate-infinispan/src/test/java/org/hibernate/test/cache/infinispan/functional/BasicTransactionalTestCase.java
This commit is contained in:
parent
31bcb0ea0a
commit
36e35207f6
|
@ -45,6 +45,8 @@ import org.hibernate.engine.spi.Status;
|
|||
import org.hibernate.internal.CoreLogging;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -349,6 +351,17 @@ public class CollectionLoadContext {
|
|||
final CollectionCacheEntry entry = new CollectionCacheEntry( lce.getCollection(), persister );
|
||||
final CacheKey cacheKey = session.generateCacheKey( lce.getKey(), persister.getKeyType(), persister.getRole() );
|
||||
|
||||
boolean isPutFromLoad = true;
|
||||
for (Serializable id : entry.getState()) {
|
||||
EntityPersister entityPersister = ((QueryableCollection) persister).getElementPersister();
|
||||
if ( session.getPersistenceContext().wasInsertedDuringTransaction( entityPersister, id ) ) {
|
||||
isPutFromLoad = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// CollectionRegionAccessStrategy has no update, so avoid putting uncommitted data via putFromLoad
|
||||
if (isPutFromLoad) {
|
||||
try {
|
||||
session.getEventListenerManager().cachePutStart();
|
||||
final boolean put = persister.getCacheAccessStrategy().putFromLoad(
|
||||
|
@ -367,6 +380,7 @@ public class CollectionLoadContext {
|
|||
session.getEventListenerManager().cachePutEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void cleanup() {
|
||||
if ( !localLoadingCollectionKeys.isEmpty() ) {
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.hibernate.NaturalIdLoadAccess;
|
|||
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;
|
||||
|
@ -46,7 +45,6 @@ import org.hibernate.cache.spi.entry.CacheEntry;
|
|||
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.assertEquals;
|
||||
|
@ -307,7 +305,6 @@ public class BasicTransactionalTestCase extends AbstractFunctionalTestCase {
|
|||
}
|
||||
|
||||
@Test
|
||||
@FailureExpected( jiraKey = "HHH-9231")
|
||||
public void testAddNewOneToManyElementNoInitFlushInitLeaveCacheConsistent() throws Exception {
|
||||
Statistics stats = sessionFactory().getStatistics();
|
||||
stats.clear();
|
||||
|
|
Loading…
Reference in New Issue