Bug 389923 - Foreign key violation because jointable row is not removed in unidirectional / privately owned relation
Summary: Foreign key violation because jointable row is not removed in unidirectional ...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-19 13:37 EDT by Jeroen Benckhuijsen CLA
Modified: 2022-06-09 10:02 EDT (History)
1 user (show)

See Also:


Attachments
Test case for this issue as a maven project (14.48 KB, application/zip)
2012-09-19 13:37 EDT, Jeroen Benckhuijsen CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeroen Benckhuijsen CLA 2012-09-19 13:37:58 EDT
Created attachment 221263 [details]
Test case for this issue as a maven project

See also: http://www.eclipse.org/forums/index.php/mv/msg/378122/915956/#msg_915956

I've been experiencing foreign key violation whil trying to update a set of entities. These entities together form a tree-like structure, which is saved completely in one go (CascadeType.ALL and orphanRemoval=true is set on all relations). Given the following structure (letters stand for entity types):

Code: [Select all] [Show/ hide]

A -> B -> B ... B -> C -> D -> [E,F,G]
       -> B ... B -> C -> D -> [E,F,G]



All relations are @OneToMany and bi-directional, except the relation between D and E,F,G. E, F and G share a common super class (marked as entity). The relation is privately owned/uni-directional. This relation is also configured to use a @JoinTable


The following scenario fails:
- Initially the first row is in the database and retrieved
- The first row is removed starting from the second B
- The second row is added (effectively replacing the original row)
- The complete set is stored

In the logging I case see that EclipseLink first tries to remove [E,F,G], before removing the row in the @JoinTable, causing a SQL Integraty exception obviously.

Traced from the EclipseLink (2.3.3) code, this starts from ManyToManyMapping.java line 945.

Tested EclipseLink 2.3.0 - 2.4.0, same result for each

Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=350599 seems related by the description?

- Am I expecting behaviour from JPA/EclipseLink which is outside of the spec or is this a bug?
- Any ideas for a workaround for this issue?
Comment 1 Jeroen Benckhuijsen CLA 2012-09-19 13:48:05 EDT
This issue occurs from at least 2.3.0 - 2.4.0 (tested/verified)
Comment 2 Tom Ware CLA 2012-10-30 09:31:34 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:02:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink