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

Bug 356117

Summary: read, change, clear, read results in stale object for Entities that do not use deferred locks
Product: z_Archived Reporter: Tom Ware <tom.ware>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipselink.foundation-inbox
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed fix - 2.1.x none

Description Tom Ware CLA 2011-08-29 16:10:42 EDT
Fix for bug 319162 fails for entities that do not use deferred locks

The following test case illustrates the problem:

    public void testFlushClearFindNoCascadedLock(){
        Map properties = new HashMap();
        
        EntityManager em = createEntityManager();
        beginTransaction(em);
        Address add = new Address();
        add.setCity("London");
        em.persist(add);
        commitTransaction(em);
           
        beginTransaction(em);
        add = em.find(Address.class, add.getID());
        add.setCity("Barcelona");
        em.flush();
        em.clear();
    
        add = em.find(Address.class, add.getID());
        commitTransaction(em);
        try{
            assertTrue("Address city was returned from server cache, when it should not have been", add.getCity().equals("Barcelona"));
        } finally {
            clearCache();
            em.clear();
            beginTransaction(em);
            add = em.find(Address.class, add.getID());
            em.remove(add);
            commitTransaction(em);
        }
    }

The fix appears to be to partially port the fix for Bug 301599.  Namely, this change adds a getFromLocalIdentityMap method to IdentityMapAccessor and some calls to it in our cache checking code.  Hopefully these parts of the fix can be backported independantly of the larger fix.

Note this issue is addressed by the fixes for bug 301599 in 2.2.x and later.  Filing this bug since a backport to 2.1.x may be required.
Comment 1 Tom Ware CLA 2011-08-29 16:15:20 EDT
Note, although the fix is already available in 2.2.x and later, the new regression test should be ported to those streams.
Comment 2 Tom Ware CLA 2011-08-31 10:05:38 EDT
Created attachment 202527 [details]
Proposed fix - 2.1.x

Attached is the proposed fix for the 2.1 stream.  As mentioned above, the fix already exists in all other open streams.  Only the test case will be ported to those streams.
Comment 3 Tom Ware CLA 2011-08-31 10:54:31 EDT
Fix backported to 2.1.4 as suggested above.  Test checked into all streams.

Reviewed by James Sutherland

Tested with Core and JPA LRG

Added test to EntityManagerJunitTestSuite
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:20:03 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink