Foreign key violation because jointable row is not removed [message #915956] |
Tue, 18 September 2012 09:41 |
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 14:11 |
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03871 seconds