Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 357363 - UnitOfWorkIdentityMapAccessor.getFromIdentityMap() ignores inheritance.
Summary: UnitOfWorkIdentityMapAccessor.getFromIdentityMap() ignores inheritance.
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Vikram Bhatia CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-12 06:52 EDT by Vikram Bhatia CLA
Modified: 2022-06-09 10:07 EDT (History)
2 users (show)

See Also:


Attachments
Testcase (24.32 KB, application/zip)
2011-09-12 07:15 EDT, Vikram Bhatia CLA
no flags Details
Proposed Fix including testcase (7.59 KB, patch)
2011-09-28 06:59 EDT, Vikram Bhatia CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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