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

Bug 364248

Summary: Updates to a value in an element collection map keyed by entity results in entity deletion
Product: z_Archived Reporter: Michael Keith <michael.keith>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: gabriel, gordon.yorke, vikram.jeet.bhatia
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix with testcase none

Description Michael Keith CLA 2011-11-20 21:12:01 EST
ElementCollection Map of basic values keyed by entity. 

Updating a value of a Map entry seems to be causing EL to not only remove the old row in the collection table and insert a new one with the new value, but also to attempt to delete the entity from its table as well.

Example of model:

@Entity
public class Department {
    @Id
    private int id;

    @ElementCollection
    @CollectionTable(name="EMP_SENIORITY")
    @MapKeyJoinColumn(name="EMP_ID")
    @Column(name="SENIORITY")
    private Map<Employee, Integer> seniorities;
    ...
}

Code example:

myDept.getSeniorities().put(newEmp, 1);
...
myDept.getSeniorities().put(newEmp, 2);


When modifying the value, the second put() will cause the row in EMP_SENIORITY table to be removed and a new one to be inserted, but will also then go on to try to remove the newEmp Employee row in the EMPLOYEE table.
Comment 1 Vikram Bhatia CLA 2011-11-22 11:03:49 EST
Created attachment 207373 [details]
Fix with testcase
Comment 2 Vikram Bhatia CLA 2011-11-23 03:19:35 EST
Fixed in EclipseLink main trunk (2.4) with r10447.
Comment 3 Vikram Bhatia CLA 2011-11-23 04:03:47 EST
Bug 364546 has been filed as performance enhancement for tracking delete/insert problem instead of an update.
Comment 4 Gabriel Kohen CLA 2011-11-29 16:50:48 EST
(In reply to comment #3)
> Bug 364546 has been filed as performance enhancement for tracking delete/insert
> problem instead of an update.

Hi,

I've tested the fix and it seems like addition and update of element to the map does function properly. However, removal of an element from the map does not.
The merge returns an object with the correct map. When you actually examine the database table, the element still exists in the map.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:26:38 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink