其实这个问题是在更新数据的时候出现的。
在使用getOne()并进行更新的时候就出现了这个问题。。
开始是以为是FetchType.LAZY的原因,但改成EAGER后还是没有解决。。
发现 现在对hibernate的了解远远不如以前,也可能以前没有理解透吧。
现在这个问题其实又是注解的配置问题。
@Column(name = "chapter", unique = false, nullable = true, insertable = true, updatable = true, length = 11)
public java.lang.Integer getChapter() {
return this.chapter;
}
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "chapter", nullable = true, insertable = false, updatable = false)
public WikiChapter getWikiChapter() {
return wikiChapter;
}
使用了两个chapter映射。
之前都是以chapter来操作的,如果要对WikiChapter来操作,就是个空值。所以在保存一个文章的时候除了 对chapter进行赋值,还得再去wikichaper进行赋一次,不然取不到wikichapter使用。
这还只是有小问题,但在对wikichapter进行更新的时候就出这个问题。。(如果数据库中不设置外键是没有这个问题的,但修改后,内存中没有关联的wikichapter值,就算是对wikichapter设置了新值)
其实是name = "chapter", nullable = true, insertable = false, updatable = false这个的问题,不能进行update,insert。
这两处不能都设置为true。。
所以还是以对象为准,操作对象,而不是字段。
Caused by: java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint
分享到:
相关推荐
(1452, 'Cannot add or update a child row: a foreign key constraint fails (`mxonline`.`django_admin_log`, CONSTRAINT `django_admin_log_user_id_c564eba6_fk_auth_user_id` FOREIGN KEY (`user_id`) ...
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails 这是因为你尝试删除的表中的字段被用作了其他表的外键,因此在删除这个表(父表)之前必须先删除具有外键的表(子表)...
在SSM项目中执行一个删除用户操作时报错,遂在navicat中尝试是否可以直接删除,报如下所示错误 student表的主键是selectedcourse表的外键,当需要删除student表内的一行数据时,必须在selectedcourse表内设置该外键...
网上查了很多,都说不满足主键约束啥的等等都没解决,我的问题主要是删除记录的时候删不了,最后发现是中间表的外键默认删除时是RESTRICT, 当取值为No Action或者Restrict时,则当在父表(即外键的来源表)中删除...
这篇文章主要涉及到在数据创建表时,遇到ERROR 1215 (HY000): Cannot add foreign key constraint 问题方面的内容,对于在数据创建表时,遇到同样问题感兴趣的同学可以参考一下。 一、问题的提出 创建两个表: ...
vc cannot add new numbervc cannot add new number
vs2010中Cannot find or open the PDB file简单总结
带详细解决方案说明文档,提供三种解决方式,另外包含stax2-api.jar,stax2-api-source.jar,woodstox-core-asl-4.4.1.jar,stax-ex.jar,wstx-asl-3.2.9.jar等jar文件,亲测有效。
用IAR和仿真器给板子下载程序时出现“a target cannot be selected when used in another debug session or in other applications.”解决办法及驱动。
If you encounter an empty Help Index tab after installing this update, open the d7.ohi file in the Delphi7Help folder and comment out one or more of the index entries by changing the colon in column ...
java.lang.IllegalArgumentException Cannot format given Object as a Date
We provide specific arguments that a pure library approach, in which the compiler is designed independently of threading issues, cannot guarantee correctness of the resulting code.
Cannot delete or update a parent row: a foreign key constraint fails (...) 这可能是MySQL在InnoDB中设置了foreign key关联,造成无法更新或删除数据。可以通过设置FOREIGN_KEY_CHECKS变量来避免这种情况。 SET ...
> ★BasicNameValuePair cannot be resolved to a type > ★HttpPost cannot be resolved to a type > ★NameValuePair cannot be resolved to a type > ★HttpClient cannot be resolved to a type > ★Http cannot...
主要介绍了Mysql错误Cannot find or open table x/x from the internal问题解决方法,需要的朋友可以参考下
这个问题曾困扰了我一段时间,无意中看到了网上的一篇文章,看完后真是觉得惭愧啊!还是平时的粗心大意造成的啊!
Linux编译静态链接出现:/usr/bin/ld: cannot find -lc. 将libc.a拷贝到usr/lib/中,问题得以解决。
解决Cannot find module '@sentry/webpack-plugin',Cannot find module '@sentry/browser',Cannot find module '@sentry/cli'等问题。 下载后,解压后文件夹,放在vue项目的node_modules文件夹下,即可。
linux压缩工具,是unzip,可以用于Linux解压文件。