今天报了这个异常,这是页面报的

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.的更多相关文章

  1. 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 ...

  2. 【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 ...

  3. 报错: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 ...

  4. org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query

    原因: 这个问题的解决方案很简单,主要是因为数据库中不存在相关的表或者列. org.springframework.dao.InvalidDataAccessApiUsageException: Pa ...

  5. 【异常】Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException

    Caused by: java.lang.ClassNotFoundException: org.springframework.dao.DataIntegrityViolationException ...

  6. org.springframework.dao.DataIntegrityViolationException:

    数据库用的hibernate,开发工具用的myeclipse,使用开发工具连接数据库生成hibernate基于xml的po类,运行时报org.springframework.dao.DataInteg ...

  7. 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 ...

  8. 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 ...

  9. 报错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 ...

随机推荐

  1. ElasticSearch 笔记(二)

    记录一些核心概念 1) Near Realtime (NRT): 近实时,包括 2 个方面,① 数据从写入 Elasticsearch 到可被搜索.分析的延迟 ( 大约 1 秒 ); ② 从 es 中 ...

  2. ubuntu14.04,安装Gnome 15.10 (桌面)

    Linux:ubuntu14.04 Gnome:15.10 更新最新版Gnome的一个好处:更新了ubuntu的软件源,我们可以使用ubuntu的软件中心获取更多需要的软件!! ubuntu默认的桌面 ...

  3. 杨辉三角的Python实现

      杨辉三角的Python实现 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 Python生成器实现杨辉三角: # python def yanghui_tr ...

  4. Navicat premium连不上Oracle的问题解决

    1.ORA-28547: 这是因为oci.dll版本不对.Navicat本地的OCI版本与Oracle服务器服务器不符造成的. 或者 打开Navicat premium客户端:Tool->Opt ...

  5. leecode刷题(5)-- 只出现一次的数字

    leecode刷题(5)-- 只出现一次的数字 只出现一次的数字 描述: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具 ...

  6. ubuntu15.04下安装docker

    ​##获得更多资料欢迎进入我的网站或者 csdn或者博客园 最近听说docker很火,不知道什么东西,只知道是一个容器,可以跨平台.闲来无事,我也来倒弄倒弄.本文主要介绍:ubuntu下的安装,以及基 ...

  7. js 简单数据类型和复杂数据类型的区别

    原始数据类型: number,string,boolean,undefined, null,object 基本类型(简单类型),值类型: number,string,boolean 复杂类型(引用类型 ...

  8. jquery 中 $('div','li')是什么意思?

     Javascript 专业回答   2013-07-18 10:59 这个写法没有错误,而且那个人跟你说的也没错,是选择li里面所有div 前面几位都学艺不精,都说错了 要搞清楚$('div','l ...

  9. sharding-jdbc数据分片配置

    数据分片 不使用Spring 引入Maven依赖 <dependency> <groupId>org.apache.shardingsphere</groupId> ...

  10. jquery实现下拉菜单

    需要实现的效果如图: <!DOCTYPE html> <html> <head lang="en"> <meta charset=&quo ...