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

Bug 328040

Summary: deletion does not work correctly for same class/cycle relationships, violates constraints
Product: z_Archived Reporter: James Sutherland <jamesssss>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P2 CC: fredt, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
fixes deletion ordering none

Description James Sutherland CLA 2010-10-18 10:10:48 EDT
A simple Tree example will fail with deletion.

If you have a Tree, Tree left, Tree right, create a Tree with children (n levels) then delete them, the deletion will fail with a constraint error.

The reason is we order deletes per class, but not per instance (as we do for inserts).  This will work correctly for privately owned I think (or maybe not...), but not for cascade delete, or just for multiple remove() calls for the parent and children.

Workaround is to null out the references from parent to child, or using flushing or multiple transactions to control the deletion order.

This really needs to be fixed.
Comment 1 Tom Ware CLA 2010-11-01 11:26:23 EDT
Setting to future P1 because this likely will not make 2.2, but should be in the next release after.
Comment 2 Tom Ware CLA 2010-11-19 13:34:55 EST
*** Bug 330580 has been marked as a duplicate of this bug. ***
Comment 3 Chris Delahunt CLA 2011-01-05 13:52:55 EST
*** Bug 331538 has been marked as a duplicate of this bug. ***
Comment 4 Tom Ware CLA 2011-01-05 13:58:47 EST
*** Bug 333476 has been marked as a duplicate of this bug. ***
Comment 5 James Sutherland CLA 2011-02-08 15:19:07 EST
Created attachment 188546 [details]
fixes deletion ordering
Comment 6 James Sutherland CLA 2011-02-08 15:20:26 EST
Fixed to track reference to deleted objects from other deleted objects in earlyPreDelete and then unravel cycles during deletion the same as insert, includes updating foreign keys to null if a cycle is detected.
Comment 7 James Sutherland CLA 2011-02-08 15:29:03 EST
SVN trunck pending commit: Bug#328040 - deletion constraint ordering

https://bugs.eclipse.org/bugs/show_bug.cgi?id=328040

Code review: Gord (pending)

Changes:
- track references from deleted objects to other deleted objects in earlyPreDelete
- changed delete to be similar to insert, have pre/post commit states and track shallow deletion
- during deletion dependent objects are first deleted, if cycle object is shallow deleted by updating foreign keys to null
- added test to delete all employees with cycle to JPA em tests
- some cleanup of commit process
- avoid executing insert/delete queries in mappings if the object was already processed
- split old-commit and new-commit methods for collection mappings
- changed CollectionChangeRecord to use List/Map generics
- fixed earlyPreDelete mappings to be inherited correctly
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:19:37 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink