[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-7113) NaturalIdLoadAccess not properly working on mutable NaturalId's

Guenther Demetz (JIRA) noreply at atlassian.com
Mon Feb 27 10:41:48 EST 2012


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

Guenther Demetz commented on HHH-7113:
--------------------------------------

In my opinion the naturalIdResolutionCacheMap must always be filled using the persister of the declaring class,
see following example:

Class A 
 NaturalId key1

Class AA extends A
 NaturalId key2

Class AAA extends AA
---------------------------


assertTrue (session.bySimpleNaturalId(A.class).load(key1) instanceof AAA); // this is possible, 
//persister of A should be considered for caching: naturalIdResolutionCacheMap.put( persisterA, entityNaturalIdResolutionCache );


assertTrue (session.byNaturalId(AA.class).using("key1", "1").using("key2", "9").load() instanceof AAA); // also this is possible,
//persister of AA should be considered for caching: naturalIdResolutionCacheMap.put( persisterAA, entityNaturalIdResolutionCache );

Thus, similiar to StatefulPersistenceContext#validateNaturalId(EntityPersister persister, Object[] naturalIdValues)
we will need a method which returns the correct persister for caching, something like following:

private EntityPersister findProperEntityPersisterForNaturalIdValues(EntityPersister persister, Object[] naturalIdValues) {
    EntityPersister ret = persister;
    while (persister.hasPersisterForSuperClass()) {
        try {
                validateNaturalId(ret.getPersisterForSuperClass(),naturalIdValues);
                ret = ret.getPersisterForSuperClass();
        }
        catch (IllegalArgumentException i) {
            break;
        }
    }
    return ret;
}

--------------------------------------------------------------------------------------------------
Then modify the puts into naturalIdResolutionCacheMap as follows:

naturalIdResolutionCacheMap.put(findProperEntityPersisterForNaturalIdValues(persister,naturalIdValues), entityNaturalIdResolutionCache );


> NaturalIdLoadAccess not properly working on mutable NaturalId's
> ---------------------------------------------------------------
>
>                 Key: HHH-7113
>                 URL: https://hibernate.onjira.com/browse/HHH-7113
>             Project: Hibernate ORM
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 4.1.0
>         Environment: Hibernate4.1.0, db independent (HSQLDB used in attached testcase)
>            Reporter: Guenther Demetz
>              Labels: naturalId
>         Attachments: EnhancedTestCaseModifieableNaturalId.jar, TestCaseModifieableNaturalId.jar
>
>   Original Estimate: 16h
>  Remaining Estimate: 16h
>
> After updating the value of a mutable NaturalId, the entity object can be retrieved with the new value, but also with the old value.
> assertNotSame(session.bySimpleNaturalId(C.class).load("1"), session.bySimpleNaturalId(C.class).load("3")); --> failing 
> See attached testcase:
> On deletions the internal NaturalId cache is synchronized properly (testDeleteNaturalId) but not on modifications (testModifieableNaturalId)

--
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