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

Bug 360372

Summary: Working with @Embeddable objects that holds an entity relation can cause duplicate-key exception
Product: z_Archived Reporter: Luca Graf <lucagraf>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: NEW --- QA Contact:
Severity: normal    
Priority: P2 CC: tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
simple maven project with test case none

Description Luca Graf CLA 2011-10-09 19:14:35 EDT
Build Identifier: 2.2.0.v20110202-r8913

Iterating over @Embeddable objects (@ElementCollection mapped as Set) who holds an entity relation (many-to-one) can cause duplicate-key exceptions. 
Under certain circumstances eclipselink try to insert also persistent 'relation objects' from the embeddable again (triggers duplicate-key exception).

Sample Model:
EntityParent 1-n > EmbeddableChild n-1 > EntityChildRelation

Sample code that causes a duplicate exception:
List<Parent> parents = em.createNamedQuery( "findAllParents", Parent.class ).getResultList();
for ( Parent parent : parents ) {
   for ( Child child : parent.getChildren() ) {
      child.getEntityRelation();
   }
   em.flush();
}

I attached a simple maven project, that contains entity classes and a unit-test (runnable in a se environment) with that the problem can be reproduced.

There still exists a more detailed forum thread about the issue: http://www.eclipse.org/forums/index.php/t/242755/.

Please note that the problem seemed to be non-deterministic (the test fails only 'most' of the time).

Reproducible: Sometimes

Steps to Reproduce:
1. Run the attached unit-test.
Comment 1 Luca Graf CLA 2011-10-09 19:15:59 EDT
Created attachment 204848 [details]
simple maven project with test case

added sample maven project
Comment 2 Tom Ware CLA 2011-10-31 13:24:55 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:34:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink