Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364248 - Updates to a value in an element collection map keyed by entity results in entity deletion
Summary: Updates to a value in an element collection map keyed by entity results in en...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-20 21:12 EST by Michael Keith CLA
Modified: 2022-06-09 10:26 EDT (History)
3 users (show)

See Also:


Attachments
Fix with testcase (11.83 KB, patch)
2011-11-22 11:03 EST, Vikram Bhatia CLA
no flags Details | Diff

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