MultiTableInfo Foreign Key Mapping Leads to ORA-02291: integrity constraint violated - parent key not found
(Doc ID 554601.1)
Last updated on MARCH 24, 2019
Applies to:
Oracle TopLink - Version 10.1.3.3 and laterInformation in this document applies to any platform.
***Checked for relevance on 15-Feb-2012***
***Checked for relevance on 27-Oct-2013***
Symptoms
Two tables are mapped with a one-to-many relationship (Master-Detail), using a MultiTableInfo descriptor.
With the given foreign key mappings, insertion into the tables using Toplink 10.1.3.3 fails with the following message:
Internal Exception: java.sql.SQLException: ORA-02291: integrity constraint (SCOTT.FK_Projects) violated - parent key not found
However, when doing the same insertion with Toplink 9.0.4 API it works fine.
Example
Here is an example structure of two such tables :
CREATE TABLE Employee (
Emp_id NUMBER(22) NOT NULL,
Name VARCHAR2(50) NOT NULL,
PRC_Projects_ID NUMBER(22) NOT NULL
);
CREATE TABLE Projects (
Pro_id NUMBER(22) NOT NULL,
Pro_Desc VARCHAR2(100)
);
CREATE SEQUENCE SN_PRO INCREMENT BY 1 START WITH 1;
ALTER TABLE Employee ADD CONSTRAINT PK_Employee PRIMARY KEY (Emp_id) USING INDEX;
ALTER TABLE Projects ADD CONSTRAINT PK_Projects PRIMARY KEY (Pro_id) USING INDEX;
ALTER TABLE Employee ADD CONSTRAINT FK_Projects FOREIGN KEY (PRC_Projects_ID) REFERENCES Projects (Pro_id);
Emp_id NUMBER(22) NOT NULL,
Name VARCHAR2(50) NOT NULL,
PRC_Projects_ID NUMBER(22) NOT NULL
);
CREATE TABLE Projects (
Pro_id NUMBER(22) NOT NULL,
Pro_Desc VARCHAR2(100)
);
CREATE SEQUENCE SN_PRO INCREMENT BY 1 START WITH 1;
ALTER TABLE Employee ADD CONSTRAINT PK_Employee PRIMARY KEY (Emp_id) USING INDEX;
ALTER TABLE Projects ADD CONSTRAINT PK_Projects PRIMARY KEY (Pro_id) USING INDEX;
ALTER TABLE Employee ADD CONSTRAINT FK_Projects FOREIGN KEY (PRC_Projects_ID) REFERENCES Projects (Pro_id);
Changes
Cause
To view full details, sign in with your My Oracle Support account. |
|
Don't have a My Oracle Support account? Click to get started! |
In this Document
Symptoms |
Example |
Changes |
Cause |
Solution |
Workaround # 1: |
Workaround # 2: |
References |