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

Bug 336280

Summary: Same object referenced from both EM cache and shared cache
Product: z_Archived Reporter: Andrei Ilitchev <andrei.ilitchev>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Andrei Ilitchev CLA 2011-02-03 15:23:25 EST
Occurs only in case CloneCopyPolicy is used (default setting for propert access).
CloneCopyPolicy creates a shalow clone of the original, then Eclipselink supposed to write into the copy the correct values.

The new object is created and persisted in EntityManager, then its copy (created using ClonecopyPolicy is placed into shared cache).

That failed at least in two cases:
1. ObjectReferenceMapping with ValueHolder. The ValueHolder on the clone is never overridden, shared with the original.
2. AggregateObjectMapping.

In both cases the result is both original (in em cache) and copy (in shared cache) reference the same object.
Comment 1 Andrei Ilitchev CLA 2011-02-03 15:52:19 EST
The bug is fixed as part of  Bug 307433 - Regression in Auditing Support when using defaults. (rev. 8929).

Note that for verification the two tests in fieldaccess.advanced.EntityManagerJUnitTestSuite testObjectReferencedInBothEmAndSharedCache_ObjectReferenceMappingVH and testObjectReferencedInBothEmAndSharedCache_AggregateObjectMapping should be run both with fieldaccess.advanced.Employee  cache settings:
the setting in fieldaccess.advanced.Employee definition:
@Cache(
     ...
    coordinationType=SEND_NEW_OBJECTS_WITH_CHANGES
)

and alternative:
@Cache(
    ...
    coordinationType=INVALIDATE_CHANGED_OBJECTS
)

The fix:

In ObjectReferenceMapping class, mergeChangesIntoObject method:
added:
        // if value holder is used, then the value holder shared with original substituted for a new ValueHolder.
        getIndirectionPolicy().reset(target);

before the last line of that method:
        setRealAttributeValueInObject(target, targetValueOfSource);

In AggregateMapping class in both mergeChangesIntoObject and mergeIntoObject methods added additional check to an if statement:
from:
        if (targetAggregate == null
to
        if (targetAggregate == null || targetAggregate == sourceAggregate
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:27:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink