Bug 303514 - ManyToMany JoinTable record is not being deleted when the mapping is inherited
Summary: ManyToMany JoinTable record is not being deleted when the mapping is inherited
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Tom Ware CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-22 11:46 EST by David Mulligan CLA
Modified: 2022-06-09 10:07 EDT (History)
5 users (show)

See Also:


Attachments
Example stack trace (5.87 KB, text/plain)
2010-02-22 11:49 EST, David Mulligan CLA
no flags Details
Proposed patch which fixes the preDeleteMapping initialization issue (1.96 KB, patch)
2010-02-22 12:12 EST, David Mulligan CLA
no flags Details | Diff
Unit Test demonstrating many to many predelete problem (12.87 MB, application/x-zip-compressed)
2010-02-22 13:00 EST, David Mulligan CLA
peter.krogh: iplog+
Details
Patch with tests (5.89 KB, patch)
2010-06-11 13:10 EDT, Tom Ware CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Mulligan CLA 2010-02-22 11:46:03 EST
Build Identifier: 2.0.1

The join table record is not deleted for a many to many mapping when the mapping is inherited from a parent descriptor.  In this case the preDeleteMapping is missing for derived ManyToManyMappings.

The preDeleteMapping property is not copied from the parent in InheritancePolicy.initialize().

Reproducible: Always

Steps to Reproduce:
1. Create a descriptor with a many to many mapping making sure to create the required foreign key constraints.  EG Person with a many to many mapping to Address.
2. Create a descriptor that inherits from the one created in step 1.  EG Employee.
3. Instantiate the child.  
4. In a new transaction try to delete it.  An sql exception is thrown complaining about a foreign key constraint violation as the join table record is not deleted so the employee record cannot be deleted.
Comment 1 David Mulligan CLA 2010-02-22 11:49:37 EST
Created attachment 159814 [details]
Example stack trace
Comment 2 David Mulligan CLA 2010-02-22 12:12:37 EST
Created attachment 159819 [details]
Proposed patch which fixes the preDeleteMapping initialization issue

I actually have two patches here.  The first is in InheritancePolicy.java which fixes the problem described and tested for in the unit test I've provided.  The second is in ClassDescriptor.clone which also does not copy the preDeleteMappings property.  I do not have a test nor a situation that proves that this is needed.  I only included it for consideration.
Comment 3 David Mulligan CLA 2010-02-22 13:00:03 EST
Created attachment 159822 [details]
Unit Test demonstrating many to many predelete problem

Extract project, run sql script and execute MyTestSuite as a junit test.
Comment 4 Tom Ware CLA 2010-03-02 11:33:55 EST
Setting target and priority.  See the following page for a description of the meanings of these values:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 5 Tom Ware CLA 2010-06-10 13:28:44 EDT
EclipseLink is designed to expect you to explicitly sever relationships before you delete objects.

If you want automatic deletions, there are a couple of options.

1. When using JPA API, you can set cascade options on your mappings that will
allow deletes to be cascaded
2. Our private owned setting will help for some mappings.
Comment 6 Tom Ware CLA 2010-06-11 09:04:16 EDT
Reopening for further investigation.
Comment 7 Tom Ware CLA 2010-06-11 13:10:36 EDT
Created attachment 171746 [details]
Patch with tests

Reinvestigated after community request.

Patch is being integrated to allow the behavior to be the same as when Inheritance is not involved.
Comment 8 Tom Ware CLA 2010-06-11 13:16:08 EDT
Checked into trunk as provided

Fix copies predeleteMappings when inheritance is involved

Reviewed by: Tom Ware - reviewed community provided fix

Added test to inheritnace test models and ran JPA and Core LRG

Setting priority to P1 and target to 2.1.1 so this fix can be integrated into 2.1.1 when that stream opens
Comment 9 Guy Pelletier CLA 2010-07-26 12:08:30 EDT
Changes have been submitted to the 2.1.1 stream.
Comment 10 Peter Krogh CLA 2010-12-08 14:25:26 EST
moving ipLog to patch
Comment 11 Eclipse Webmaster CLA 2022-06-09 10:07:58 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink