Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356117 - read, change, clear, read results in stale object for Entities that do not use deferred locks
Summary: read, change, clear, read results in stale object for Entities that do not us...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-29 16:10 EDT by Tom Ware CLA
Modified: 2022-06-09 10:20 EDT (History)
1 user (show)

See Also:


Attachments
Proposed fix - 2.1.x (8.24 KB, patch)
2011-08-31 10:05 EDT, Tom Ware CLA
no flags Details | Diff

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