ORA-02291:parent key not found
来源:互联网 发布:自己的淘宝等级怎么看 编辑:程序博客网 时间:2024/05/22 00:06
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
---------------------------------------------------------------------------------------------------------------------------
参看了这本书第八章:
《Oracle Database 11g SQL开发指南》<oracle database 11g SQL Master SQL and PL/SQL in the Oracle Database>
8.5.2 外键约束
所谓外键关系就是一个表中的列引用了其他表中的列。例如,products表中的product_type_id列引用了
product_types表中的product_type_id列。product_types表称为父表(parent table),而products表则称为子
表(child table),这是因为products表中的product_type_id列依赖于product_types表中的product_type_id
列。
如果试图向products表中插入一行,但此行的product_type_id不存在,数据库就会返回ORA-02291错误。这个错
误说明数据库无法找到一个匹配的父键值(此处父键就是product_types表中的product_type_id列)。在下面这个
例子中,就返回这样一个错误,因为product_types表中不存在product_type_id为6的行:
SQL> INSERT INTO products (
2 product_id, product_type_id, name, description, price
3 ) VALUES (
4 13, 6, 'Test', 'Test', NULL
5 );
INSERT INTO products (
*
ERROR at line 1:
ORA-02291: integrity constraint (STORE.PRODUCTS_FK_PRODUCT_TYPES)
violated - parent key not found
同理,如果试图将products表中一行的product_type_id列设置为一个不存在的父键值,数据库也会返回相同的
错误。例如:
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
如果试图从父表中删除已经有依赖子行的一行,数据库就会返回ORA-02292错误。例如,如果试图删除
product_types表中 product_type_id列为1的行,数据库就会返回ORA-02292错误,因为products表中包含了
product_type_id列等于1的行:
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
如果数据库允许执行这个删除操作,那么子行就无效了,因为它们不能指向父表中的有效值了。
---------------------------------------------------------------------------------------------------------------------
后来发现是在表中外键设置错误造成的,引以为戒:
转自:http://hi.baidu.com/skyforum/blog/item/37611a2e25a8205a4ec2262f.html
- ORA-02291:parent key not found
- ORA-02291: integrity constraint: parent key not found
- ORA-02298 Parent Keys Not Found?解决办法
- 解决ORA-08102: index key not found
- ORA-08102: index key not found
- ORA-02291: integrity constraint (INFORES_GZ_PJ2.FK_TC_DEV_PROPERTY_GRP_PROID) violated - parent key
- ora-08102:index key not found,obj#57848,file 6, block 6324(2)
- ORA-08102:index key not found, obj# 52485, file 19,block 399461 (2)
- ORA-08102: index key not found, obj# 129038, file 78, block 2910787 (2)
- java.sql.SQLException: ORA-08102: index key not found, obj# 80756, file 18, block 35018 (2)
- RSA private key file not found
- 安装RVM失败: public key not found
- 安装RVM失败: public key not found
- RSA private key file not found
- RuntimeWarning: Parent module 'settings' not found while handling absolute import
- unittest RuntimeWarning: Parent module '' not found while handling absolute import
- 解决 RuntimeWarning: Parent module '...' not found while handling absolute import
- ORA-01403 :not data found 处理方式
- html
- hibernate通用方法
- MFC界面开发笔记
- Linux服务cannot change directory错误解决方法
- Ubuntu9.10下编译Android源码
- ORA-02291:parent key not found
- POJ3712Edges and More Edges
- android.webkit.WebView 使用 SINGLE_COLUMN layout algorithm 导致程序意外退出的解决办法
- 設計カバレッジで漏れの確認
- python 俄罗斯方块
- 阿里巴巴面试三题目其二的个人理解
- PowerDesigner12.5下载及破解
- busybox使用
- 梦中思伊人