Ora-02291:parent Key not found

Source: Internet
Author: User
Tags one table


Hibernate operation:could not execute JDBC batch update; SQL [INSERT INTO

Dchnpricecarchancesource (inpricecard_id, pricecard_id, Count, Sumcount, Source_code, Reason_code,

ingroup_id, Op_login, Op_groupid, Op_time, Change_source, Memo1, Memo2, change_id) VALUES (?,?,

?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; Ora-02291:integrity constraint

(Dbchnadm. fk_dchnpric_reference_dchnpric) violated-parent key not found; Nested exception is

Java.sql.batchupdateexception:ora-02291:integrity constraint

(Dbchnadm. fk_dchnpric_reference_dchnpric) violated-parent key not found

--------------------------------------------------------------------------------------------------------------- ------------

See the eighth chapter of the book:
Oracle Database 11g SQL Development Guide <oracle Database 11g SQL Master SQL and pl/sql in the Oracle database>

8.5.2 FOREIGN KEY constraint

A foreign-key relationship is a column in one table that references a column in another table. For example, the product_type_id column in the Products table references the

Product_types the product_type_id column in the table. The Product_types table is called the parent table, and the Products table is called the child

Table (child table) because the product_type_id column in the Products table relies on the product_type_id in the Product_types table

Column.

If you try to insert a row into the Products table, but the product_type_id of this row does not exist, the database returns a ORA-02291 error. This mistake

Error description The database could not find a matching parent key value (where the parent key is the product_type_id column in the Product_types table). In the following

example, this error is returned because a row with product_type_id 6 does not exist in the Product_types table:

Sql> INSERT into the products (
2 product_id, product_type_id, name, description, price
3) VALUES (
4, 6, ' Test ', ' Test ', NULL
5);
INSERT into the products (
*
ERROR at line 1:
Ora-02291:integrity constraint (STORE. Products_fk_product_types)
Violated-parent Key not found

Similarly, if you attempt to set the product_type_id column of a row in the Products table to a nonexistent parent key value, the database returns the same

Error. For example:

Sql> UPDATE Products
2 SET product_type_id = 6
3 WHERE product_id = 1;
UPDATE Products
*
ERROR at line 1:
Ora-02291:integrity constraint (STORE. Products_fk_product_types)
Violated-parent Key not found

If you attempt to delete a row that already has dependent child rows from the parent table, the database returns a ORA-02292 error. For example, if you try to delete

The product_type_id column in the Product_types table is a row of 1, and the database returns a ORA-02292 error because the Products table contains

product_type_id column equals 1 line:

Sql> DELETE from Product_types
2 WHERE product_type_id = 1;
DELETE from Product_types
*
ERROR at line 1:
Ora-02292:integrity constraint (STORE. Products_fk_product_types)
Violated-child Record found

If the database allows this deletion to take effect, then the child rows are invalid because they cannot point to valid values in the parent table.

--------------------------------------------------------------------------------------------------------------- ------

Later found to be in the table of the foreign key set error caused by the warning:

Turn from: http://hi.baidu.com/skyforum/blog/item/37611a2e25a8205a4ec2262f.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.