Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 357363

Summary: UnitOfWorkIdentityMapAccessor.getFromIdentityMap() ignores inheritance.
Product: z_Archived Reporter: Vikram Bhatia <vikram.jeet.bhatia>
Component: EclipselinkAssignee: Vikram Bhatia <vikram.jeet.bhatia>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: gordon.yorke, vikram.jeet.bhatia
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Testcase
none
Proposed Fix including testcase none

Description Vikram Bhatia CLA 2011-09-12 06:52:58 EDT
UnitOfWorkIdentityMapAccessor.getFromIdentityMap() ignores inheritance. If identityMaps are not initialized in UOW, and it checks parent session identityMaps for the cacheKey, it doesn't take inheritance into consideration, and returns the object of the wrong class.

A - Base Class.
B extends A.
C extends A.

        EntityManager em = createEntityManager();
        em.getTransaction().begin();
        
        Session session = ((EntityManagerImpl) em).getActiveSession();
        
        UnitOfWork uow = session.acquireUnitOfWork();

        ReadObjectQuery vQuery = new ReadObjectQuery(C.class);
        vQuery.setShouldRefreshIdentityMapResult(true);
        
        // read some SmallProject and ensure it's present in shared cache
        C vSmallProject = (C)uow.getParent().executeQuery(vQuery);

        long vId = vSmallProject.getId();

        Object vResult = null;
        // ask uow.IdentityMap for a LargeProject with PrimaryKey vId. There is no LargeProject with this key.
        vResult = uow.getIdentityMapAccessor().getFromIdentityMap(vId, B.class, false);
        if (vResult instanceof C) {
            System.out.println("\n\nFound Wrong Class Object : " + vResult + "\n\n");
        }
Comment 1 Vikram Bhatia CLA 2011-09-12 07:15:25 EDT
Created attachment 203139 [details]
Testcase

Steps to Reproduce:
1. Changes database details in sessions.xml.
2. Import project in eclipse, and change DB driver and eclipselink.jar in classpath.
3. Run ResetDatabase to setup database.
4. Run Example to notice the issue.
Comment 2 Vikram Bhatia CLA 2011-09-28 06:59:11 EDT
Created attachment 204165 [details]
Proposed Fix including testcase
Comment 3 Vikram Bhatia CLA 2011-09-28 07:49:11 EDT
Fixed in EclipseLink trunk (2.4.0) with r10183.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:02:44 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:07:23 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink