org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.
今天报了这个异常,这是页面报的
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.
控制台报
18:52:35,859 ERROR SqlExceptionHelper:147 - Cannot delete or update a parent row: a foreign key constraint fails (`zl_cms`.`t_channel`, CONSTRAINT `FK_8xberajm2i2c97rwrellh0eqk` FOREIGN KEY (`pid`) REFERENCES `t_channel` (`id`)
channel对象自关联
<hibernate-mapping package="com.zl.cms.model">
<class name="Channel" table="t_channel">
<id name="id">
<generator class="identity"/>
</id>
<property name="name" type="string"/>
<property name="customLink" type="int" column="custom_link"/>
<property name="customLinkUrl" type="string" column="custom_link_url"/>
<property name="index" type="int" column="is_index"/>
<property name="topNav" type="int" column="is_top"/>
<property name="status" type="int"/>
<property name="recommed" type="int"/>
<property name="orders" type="int"/>
<many-to-one name="parent" column="pid" cascade="all" class="Channel"/>
<property name="type">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.zl.cms.model.ChannelType</param>
<param name="type">4</param>
</type>
</property>
</class>
</hibernate-mapping>
原因是 hibernate级联删除问题。
<many-to-one name="parent" column="pid" cascade="all" class="Channel"/> 这里设置了all ,应该设置成none不进行级联操作
,这个和数据库还是有区别
数据库外键检查。一般情况是,当你删除父键时,不让删除,因为有子键引用这个父建id,但是hibernate的级联不一样。删除子键也不行 ,所以取消级联
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.的更多相关文章
- SpringBoot保存数据报错:could not execute statement; SQL [n/a]; constraint [PRIMARY];nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
使用SpringBoot做JAVA开发时,用Repository.save();保存数据的时候遇到了报错: could not execute statement; SQL [n/a]; constr ...
- 【hibernate】报错:org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement
报错如下: org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a ...
- 报错:org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n ...
- org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
原因: 这个问题的解决方案很简单,主要是因为数据库中不存在相关的表或者列. org.springframework.dao.InvalidDataAccessApiUsageException: Pa ...
- 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException
Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...
- org.springframework.dao.DataIntegrityViolationException:
数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...
- HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
1.什么操作出现:当我在项目中添加产品或者修改时,浏览器出现HTTP Status 500 - Request processing failed; nested exception is org.h ...
- org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: sys.entity.Role; nested exception is org.hibernate.PersistentObjectException: 的解决方案
1.错误信息 org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist ...
- 报错org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"
org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...
随机推荐
- HTML5+CSS3从入门到精通 中文pdf版
HTML5+CSS3从入门到精通是通过基础知识+中小实例+综合案例的方式,讲述了用HTML5+ CSS3设计构建网站的必备知识,相对于专业指南.高级程序设计.开发指南同类图书,本书是一本适合快速入手的 ...
- 利用Response.Buffer做类似异步效果
在page_load加入以下代码 Response.Buffer = false; //这句话非常重要 for (int i = 0; i < 10; i++) { Thread.Sleep( ...
- 多个fragment中重叠问题的解决方法
这个方法适用性有限. 我的是一个mainActivity,然后下部四个按钮,点击时先隐藏所有的fragment,然后再new一个新的出来,如果存在,则直接显示出来,看上去一切都没有问题. 但是通过fr ...
- docker run hello-world失败
提示镜像拉取失败,解决方案 到 https://cr.console.aliyun.com/ 注册一个账户 列表中就有 加速器 启动 Docker 端 右键 选择配置 在Docker Dae ...
- 图像中的掩膜(Mask)是什么
在图像处理中,经常会碰到掩膜(Mask)这个词.那么这个词到底是什么意思呢?下面来简单解释一下. 1.什么是掩膜 首先我们从物理的角度来看看mask到底是什么过程. 在半导体制造中,许多芯片工艺步骤采 ...
- CHNetRequest网络请求
Paste JSON as Code • quicktype 软件的使用 iOS开发:官方自带的JSON使用 JSON 数据解析 XML 数据解析 Plist 数据解析 NetRequest 网络数据 ...
- Scala详细环境安装与配置
https://blog.csdn.net/free356/article/details/72911898 系统为windows.安装配置Scala如下: 一,安装Scala 1,java6以上(建 ...
- Spring IOC容器交给application域对象管理
在项目开发中,我们不能在每次使用IOC容器时,都创建一个ApplicationContext对象, 因此我们将IOC容器交给application域对象管理,application对象在服务器启动时创 ...
- 下载azure website的code
1.登陆kudu直接下载. http://www.concurrency.com/blog/use-azure-kudu-debug-azure-websites/ 2.FTP链接拷贝(可以忽略) 3 ...
- Python3之random模块
一.简介 ramdom模块提供了一个随机数的函数:random() 它可以返回一个随机生成的实数,范围在[0,1)范围内.需要注意的是random()是不能直接访问的,需要导入模块random才可以使 ...