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

Bug 340802

Summary: merge problem: existing object referenced by new not cascade merged
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:
Attachments:
Description Flags
suggested patch
none
suggested patch - take 2 none

Description Andrei Ilitchev CLA 2011-03-23 16:22:01 EDT
A has OneToOne to B with cascade merge.

Create and persist a new B, close the EntityManager - the B is now detached.

Create a new A, make it reference the B, change state of the B.
Merge the A in a new EntityManager.

Result:
B is not merged - still has an old state both in cache and data base.
Comment 1 Andrei Ilitchev CLA 2011-03-23 17:08:41 EDT
Created attachment 191796 [details]
suggested patch

The patch was suggested by James: in UnitOfWorkImpl.internalRegisterObject add registeredObject to newMergedObjects only if it's a new object.
Comment 2 Andrei Ilitchev CLA 2011-03-23 17:15:33 EDT
Created attachment 191797 [details]
suggested patch - take 2

Adding a file forgotten in the first patch.
Comment 3 Andrei Ilitchev CLA 2011-03-23 17:32:54 EDT
Checked into trunk.
Added EntityManagerJUnitTestSuite.testMergeNewReferencingOldChanged
Also added testMergeNewReferencingOldChangedClearCache - for now commented out until (closely related) bug 340810 - merge problem: existing object referenced by new not cascade merged if not in cache  is fixed.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:22:46 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink