Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 336280 - Same object referenced from both EM cache and shared cache
Summary: Same object referenced from both EM cache and shared cache
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-02-03 15:23 EST by Andrei Ilitchev CLA
Modified: 2022-06-09 10:27 EDT (History)
0 users

See Also:


Attachments

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