mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-16 16:15:06 +00:00
HHH-8410 NaturalIdXrefDelegate could miss some cached entries from naturalIdResolutionCacheMap
This commit is contained in:
parent
168c06d062
commit
8aff7db2e0
@ -55,7 +55,7 @@ public class NaturalIdXrefDelegate {
|
|||||||
private static final Logger LOG = Logger.getLogger( NaturalIdXrefDelegate.class );
|
private static final Logger LOG = Logger.getLogger( NaturalIdXrefDelegate.class );
|
||||||
|
|
||||||
private final StatefulPersistenceContext persistenceContext;
|
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
|
* Constructs a NaturalIdXrefDelegate
|
||||||
@ -92,7 +92,10 @@ public boolean cacheNaturalIdCrossReference(EntityPersister persister, Serializa
|
|||||||
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
|
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
|
||||||
if ( entityNaturalIdResolutionCache == null ) {
|
if ( entityNaturalIdResolutionCache == null ) {
|
||||||
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
|
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
|
||||||
naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
|
NaturalIdResolutionCache previousInstance = naturalIdResolutionCacheMap.putIfAbsent( persister, entityNaturalIdResolutionCache );
|
||||||
|
if ( previousInstance != null ) {
|
||||||
|
entityNaturalIdResolutionCache = previousInstance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return entityNaturalIdResolutionCache.cache( pk, naturalIdValues );
|
return entityNaturalIdResolutionCache.cache( pk, naturalIdValues );
|
||||||
}
|
}
|
||||||
@ -279,7 +282,10 @@ public Serializable findCachedNaturalIdResolution(EntityPersister persister, Obj
|
|||||||
|
|
||||||
if ( entityNaturalIdResolutionCache == null ) {
|
if ( entityNaturalIdResolutionCache == null ) {
|
||||||
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
|
entityNaturalIdResolutionCache = new NaturalIdResolutionCache( persister );
|
||||||
naturalIdResolutionCacheMap.put( persister, entityNaturalIdResolutionCache );
|
NaturalIdResolutionCache existingCache = naturalIdResolutionCacheMap.putIfAbsent( persister, entityNaturalIdResolutionCache );
|
||||||
|
if ( existingCache != null ) {
|
||||||
|
entityNaturalIdResolutionCache = existingCache;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, cachedNaturalId );
|
entityNaturalIdResolutionCache.pkToNaturalIdMap.put( pk, cachedNaturalId );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user