| Summary: | UnitOfWorkIdentityMapAccessor.getFromIdentityMap() ignores inheritance. | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | Vikram Bhatia <vikram.jeet.bhatia> | ||||||
| Component: | Eclipselink | Assignee: | 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: |
|
||||||||
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.
Created attachment 204165 [details]
Proposed Fix including testcase
Fixed in EclipseLink trunk (2.4.0) with r10183. The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |
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"); }