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

Bug 357670

Summary: Lazy Basic Mapping not properly loaded after create, flush, refresh, commit
Product: z_Archived Reporter: Tom Ware <tom.ware>
Component: EclipselinkAssignee: Tom Ware <tom.ware>
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 none

Description Tom Ware CLA 2011-09-14 14:33:54 EDT
If you have a LAZY Basic mapping and populate it in a new object.  A call to flush and then refresh can corrupt it in the shared cache.  Here is a test case for our DDL Generation Model:

    // Bug 
    public void testLazyBlob(){
        EntityManager em = createEntityManager(DDL_TPC_PU);
        beginTransaction(em);
        LuxuryCar car = new LuxuryCar();
        try {
            java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
            java.io.PrintWriter pw = new java.io.PrintWriter(baos);
            pw.print("TestString1");
            pw.close();
            baos.close();
            car.setPic( baos.toByteArray());
        }
        catch (Exception e) {
            e.printStackTrace();
            fail("we failed!!!");
        }
        em.persist(car);
        em.flush();
        em.refresh(car);
        commitTransaction(em);
        em.clear();
        
        car = em.find(LuxuryCar.class, car.getRegNumber());
        byte[] pic = car.getPic();
        assertTrue("Blob was null after flush, refresh, commit.", pic != null);
    }
Comment 1 Tom Ware CLA 2011-09-14 14:45:21 EDT
Created attachment 203357 [details]
proposed fix
Comment 2 Tom Ware CLA 2011-09-15 10:07:15 EDT
Proposed fix propogates change set to a newly built clone from the source during the merge.

Checked into trunk

Reviewed by Andrei Ilitchev

Added test to DDLGenerationTestSuite

Tested with Core and JPA LRG

2.3, 2.2 and 2.1 check-ins to follow.
Comment 3 Tom Ware CLA 2011-09-15 14:56:24 EDT
Retargetting.  Backport is risky due to amount of supporting API that needs to be backported to get the session need to deal with the fetch group.

Changes checked into 2.3.1
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:08:40 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink