Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Foreign key violation because jointable row is not removed
icon5.gif  Foreign key violation because jointable row is not removed [message #915956] Tue, 18 September 2012 05:41 Go to next message
Jeroen Benckhuijsen is currently offline Jeroen Benckhuijsen
Messages: 3
Registered: September 2012
Junior Member
Hi,

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):

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 (which seems strange, the mapping is OneToMany??).

Tested EclipseLink 2.3.0 - 2.3.3, same result for each

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

Any ideas?
- 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?

Thanks.

Jeroen
Re: Foreign key violation because jointable row is not removed [message #916090 is a reply to message #915956] Tue, 18 September 2012 10:11 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This issue may have been fixed, please try the latest 2.4 release.

Otherwise you could log a bug with your complete information, log on finest, model, test.

Please include the log on finest.

The ManyToManyMapping is normal, internal a OneToMany with a JoinTable uses the ManyToManyMapping class.

Try narrowing down the issue. Does it occur if you remove the inheritance, or remove the orphanRemoval? Are you using JOINED inheritance, what if you use TABLE?

In general you can avoid constraint issues by using flush() to control the order of execution, or removing the constraint on the database.



James : Wiki : Book : Blog : Twitter
Re: Foreign key violation because jointable row is not removed [message #916319 is a reply to message #916090] Tue, 18 September 2012 18:14 Go to previous messageGo to next message
Jeroen Benckhuijsen is currently offline Jeroen Benckhuijsen
Messages: 3
Registered: September 2012
Junior Member
The bug is still present in 2.4.0. I've created a selfcontained test case for this issue. The issue specifically occurs when trying to delete starting from B or C (and probably A) and letting EclipseLink handle the cascade from there, (given the above description). Performing a delete starting from D works correctly. This can also be seen in the logging, where in the latter case, there is a SQL statement for removal of the row from the JoinTable.

I can create a bug report for this with the attached test case, It's a maven project with example entities and four JUnit tests, two of them failing to show the issue if that might help solving this?
Re: Foreign key violation because jointable row is not removed [message #916978 is a reply to message #916319] Wed, 19 September 2012 13:47 Go to previous message
Jeroen Benckhuijsen is currently offline Jeroen Benckhuijsen
Messages: 3
Registered: September 2012
Junior Member
Bug filed at: https://bugs.eclipse.org/bugs/show_bug.cgi?id=389923 including test cases
Previous Topic:JTA/XA
Next Topic:Large network traffic in comparission to SQL-Developer
Goto Forum:
  


Current Time: Sun Apr 20 04:16:40 EDT 2014

Powered by FUDForum. Page generated in 0.01588 seconds