Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 360372 - Working with @Embeddable objects that holds an entity relation can cause duplicate-key exception
Summary: Working with @Embeddable objects that holds an entity relation can cause dupl...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P2 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-10-09 19:14 EDT by Luca Graf CLA
Modified: 2022-06-09 10:34 EDT (History)
1 user (show)

See Also:


Attachments
simple maven project with test case (28.90 KB, application/zip)
2011-10-09 19:15 EDT, Luca Graf CLA
no flags Details

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