Tag Archives: ORA-02291 error

Java.sql.SQLException: ORA-02291: integrity constraint violated – par

java.sql.SQLException: ORA-02291: integrity constraint (BOOKER.FK_ANDON_EVENT_STATUS) violated – parent key not found
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1168)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3316)
from: http://www.dba-oracle.com/t_ora_02291_integrity_constraint_string_string_violated_parent_key_not_found.htm

The Oracle docs note this on the ora-02291 error:
ORA-02291: integrity constraint (string.string) violated – parent key not found

Cause: A foreign key value has no matching primary key value.
Action: Delete the foreign key or add a matching primary key.

For an insert statement, this ORA-02291 error is common when you are trying to insert a child without a matching parent, as defined by a foreign key constraint.  In that case, you need to add the parent row to the table and then re-insert your child table row.
See the dba_constraints view to find the parent table.

To fully understand [primary and foreign key constraints, see the book Easy Oracle Jumpstart, to explain these concepts:

Entity integrity error
Your foreign key FK_ANDON_EVENT_STATUS will be wrong if there is no data in the column of the corresponding parent table, you should insert the parent table first, then insert the child table
Table a has a foreign key, pointing to table b, then b is the parent table of a, the foreign key refers to the column is the parent key