Bug 495633 - Multiple ManyToMany Mapping to same Entity type causes SQLException
Summary: Multiple ManyToMany Mapping to same Entity type causes SQLException
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-07 16:41 EDT by Alex Mortimer CLA
Modified: 2022-06-09 10:07 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alex Mortimer CLA 2016-06-07 16:41:31 EDT
When one entity defines two separate ManyToMany relationships of the same entity type, a join table is created containing three columns. 

Here is an example:

public class EntityA {

@ManyToMany
private List<EntityB> list1;

@ManyToMany
private List<EntityB> list2;

}

This results in EclipseLink creating the following join table:

CREATE TABLE ENTITYA_ENTITYB (EntityA_ID INTEGER NOT NULL, list1_ID INTEGER NOT NULL, list2_ID INTEGER NOT NULL, PRIMARY KEY (EntityA_ID, list1_ID, list2_ID))

The issue is that EclipseLink is creating the join table's columns with a NOTNULL constraint. Then, when EclipseLink inserts values into the table, it will only insert values for two of the columns at a time and will leave the third value as null.  This causes an SQLException since the table columns are created with a NOTNULL constraint.
Comment 1 Eclipse Webmaster CLA 2022-06-09 10:07:54 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink