cannot add or update a child row: a foreign key constraint fails

来源:百度知道 编辑:UC知道 时间:2024/06/19 00:05:32
麻烦一下 我的产品类型和产品一对多 产品和销售信息 一对多 销售商和销售信息 一对多 请问这个出现 Cannot add or update a child row: a foreign key constraint fails 大概是什么原因啊?麻烦一下 我的产品类型和产品一对多 产品和销售信息 一对多 销售商和销售信息 一对多 请问这个出现
2008-11-13 8:10:41 org.hibernate.util.JDBCExceptionReporter logExceptions
警告: SQL Error: 1452, SQLState: 23000
2008-11-13 8:10:41 org.hibernate.util.JDBCExceptionReporter logExceptions
严重: Cannot add or update a child row: a foreign key constraint fails (`forthtests/aasell`, CONSTRAINT `FKAB12CB72FE00B749` FOREIGN KEY (`sell_id`) REFERENCES `aabuy` (`buy_id`))
Exception in thread "main" org.hibernate.exception.ConstraintViolationException: could not insert: [model.Sell]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(

这个问题一定是由 销售信息 与 产品、销售商 之间的 外键关联造成的。

从错误讯息来看,有可能是你在保存或者修改一份 销售信息 的时候,没有填充 销售商 的讯息,或者填充了一个资料库中没有的 销售商 讯息。

希望你能描述一下你正在进行的操作。

如果用Hibernate处理资料表的关联十分棘手的话,你可以尝试删除资料库端的表关联,然后通过Hibernate的配置文件建立表关联,用程式端的表关联控制资料库端的表关联。