[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7160) NaturalIdXrefDelegate#cache() needs to remove obsolete entries in shared cache when NaturalId values changed

Guenther Demetz (JIRA) noreply at atlassian.com
Fri Mar 16 03:35:48 EDT 2012


    [ https://hibernate.onjira.com/browse/HHH-7160?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45982#comment-45982 ] 

Guenther Demetz commented on HHH-7160:
--------------------------------------

Following the instructions how to fix this issue:

1. Modify NaturalIdResolutionCache#cache by adding session as third parameter and adding the block after 'if ( persister.hasNaturalIdCache()':

{code:title=NaturalIdResolutionCache.java|borderStyle=solid}
public boolean cache(Serializable pk, Object[] naturalIdValues, SessionImplementor session) {
			final CachedNaturalId initial = pkToNaturalIdMap.get( pk );
			if ( initial != null ) {
				if ( areSame( naturalIdValues, initial.getValues() ) ) {
					return false;
				}
				naturalIdToPkMap.remove( initial );  
				
				if ( persister.hasNaturalIdCache() ) {
					final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( initial.getValues(), persister, session );
					persister.getNaturalIdCacheAccessStrategy().evict( naturalIdCacheKey );
				}
			}

			final CachedNaturalId cachedNaturalId = new CachedNaturalId( persister, naturalIdValues );
			pkToNaturalIdMap.put( pk, cachedNaturalId );
			naturalIdToPkMap.put( cachedNaturalId, pk );
			
			return true;
		}
{code}


2. Add session as 3hrd parameter (around line 81 in NaturalIdXrefDelegate.java) 
{code:title=NaturalIdXrefDelegate.java|borderStyle=solid}

final boolean justAddedToLocalCache = entityNaturalIdResolutionCache.cache( pk, naturalIdValues, persistenceContext.getSession() );
{code}

> NaturalIdXrefDelegate#cache() needs to remove obsolete entries in shared cache when NaturalId values changed
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: HHH-7160
>                 URL: https://hibernate.onjira.com/browse/HHH-7160
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 4.1.1
>         Environment: Hibernate4.1.1
>            Reporter: Guenther Demetz
>            Assignee: Steve Ebersole
>              Labels: naturalId
>             Fix For: 4.1.2
>
>         Attachments: TestCaseNaturalIdChangeBetweenPersistAndFlush.jar
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Method NaturalIdXrefDelegate#cache() misses to remove obsolete entry in naturalIdToPkMap when NaturalId values changed,
> thus NaturalIdAccess delivers results even by searching with obsolete values (see attached Testcase).
> Cause:
> following instruction is missing in Method NaturalIdXrefDelegate#cache():
> if ( initial != null ) {
> 	if ( areSame( naturalIdValues, initial.getValues()) ) {
> 		return false;
> 	}
> 	naturalIdToPkMap.remove(initial); // <-- this instruciton is missing
> }

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list