Skip to content

Commit

Permalink
HHH-8410 NaturalIdXrefDelegate could miss some cached entries from na…
Browse files Browse the repository at this point in the history
…turalIdResolutionCacheMap
  • Loading branch information
Sanne committed Aug 2, 2013
1 parent 168c06d commit 8aff7db
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -55,7 +55,7 @@ public class NaturalIdXrefDelegate {
private static final Logger LOG = Logger.getLogger( NaturalIdXrefDelegate.class );

private final StatefulPersistenceContext persistenceContext;
private final Map<EntityPersister, NaturalIdResolutionCache> naturalIdResolutionCacheMap = new ConcurrentHashMap<EntityPersister, NaturalIdResolutionCache>();
private final ConcurrentHashMap<EntityPersister, NaturalIdResolutionCache> naturalIdResolutionCacheMap = new ConcurrentHashMap<EntityPersister, NaturalIdResolutionCache>();

/**
* Constructs a NaturalIdXrefDelegate
Expand Down Expand Up @@ -92,7 +92,10 @@ public boolean cacheNaturalIdCrossReference(EntityPersister persister, Serializa
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
if ( entityNaturalIdResolutionCache == null ) {
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
NaturalIdResolutionCache previousInstance = naturalIdResolutionCacheMap.putIfAbsent( persister, entityNaturalIdResolutionCache );
if ( previousInstance != null ) {
entityNaturalIdResolutionCache = previousInstance;
}
}
return entityNaturalIdResolutionCache.cache( pk, naturalIdValues );
}
Expand Down Expand Up @@ -279,7 +282,10 @@ public Serializable findCachedNaturalIdResolution(EntityPersister persister, Obj

if ( entityNaturalIdResolutionCache == null ) {
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
NaturalIdResolutionCache existingCache = naturalIdResolutionCacheMap.putIfAbsent( persister, entityNaturalIdResolutionCache );
if ( existingCache != null ) {
entityNaturalIdResolutionCache = existingCache;
}
}

entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, cachedNaturalId );
Expand Down

0 comments on commit 8aff7db

Please sign in to comment.