MultiTableInfo Foreign Key Mapping Leads to ORA-02291: integrity constraint violated - parent key not found (Doc ID 554601.1)

Last updated on MARCH 12, 2015

Applies to:

Oracle TopLink - Version 10.1.3.3 and later
Information 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_SECONDARY) 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 PRINCIPAL (
ID_PRC NUMBER(22) NOT NULL,
PRC_NAME VARCHAR2(50) NOT NULL,
PRC_SECONDARY_ID NUMBER(22) NOT NULL
);

CREATE TABLE SECONDARY (
ID_SCN NUMBER(22) NOT NULL,
SCN_DESC VARCHAR2(100)
);

CREATE SEQUENCE SN_WAT INCREMENT BY 1 START WITH 1;

ALTER TABLE PRINCIPAL ADD CONSTRAINT PK_PRINCIPAL PRIMARY KEY (ID_PRC) USING INDEX;

ALTER TABLE SECONDARY ADD CONSTRAINT PK_SECONDARY PRIMARY KEY (ID_SCN) USING INDEX;

ALTER TABLE PRINCIPAL ADD CONSTRAINT FK_SECONDARY FOREIGN KEY (PRC_SECONDARY_ID) REFERENCES SECONDARY (ID_SCN);

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms