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

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. [原创]Java源代码学习

    一.一些关键字 方法声明中的native:调用本地方法,该方法一般是用C或者C++写的 变量声明中的transient:在序列化过程中会忽略该变量,即不进行序列化保存 变量声明中的volatile:编 ...

  2. sql 与 oracle 几个简单语法差别

    sql 与 oracle 之间的 语法差别. 简单的几个函数转换 sql->  Up_Time=getdate(),  isnull(), substring(),  charindex(), ...

  3. HTML5和CSS3实例教程 中文版 高清PDF扫描版

    HTML5和CSS3实例教程共分3部分,集中讨论了HTML5和CSS3规范及其技术的使用方法.首先是规范概述,介绍了新的结构化标签.表单域及其功能(包括自动聚焦功能和占位文本)和CSS3的新选择器.接 ...

  4. C#winform拖动无边框窗体

    private bool isMouseLeftKeyDown = false; private Point mousePointToClient = new Point();//相对于本窗体鼠标位置 ...

  5. 基于zookeeper实现高性能分布式锁

    实现原理:利用zookeeper的持久性节点和Watcher机制 具体步骤: 1.创建持久性节点 zkLock 2.在此父节点下创建子节点列表,name按顺序定义 3.Java程序获取该节点下的所有顺 ...

  6. Android Studio无法找到tool.jar解决方法!

    今天安装并配置了JDK,可以在DOS窗口中使用“java -version”命令查看JAVA版本信息了,随后安装Android Studio,但是等Android Studio安装完毕,启动时候发现, ...

  7. Kubernetes 集群部署(3) -- Flannel 集群

    1. 下载包 wget https://github.com/coreos/flannel/releases/download/v0.11.0/flannel-v0.11.0-linux-amd64. ...

  8. bootstrap表单控件

    禁用状态: 被禁用的 fieldset 为<fieldset> 设置 disabled 属性,可以禁用 <fieldset> 中包含的所有控件. <form> &l ...

  9. python学习之路---day18--反射

    一:isinstance,type,issubclass  001:内置函数:isinstance() class Base: pass class Foo(Base): pass class Bar ...

  10. [FJOI2017]矩阵填数

    [Luogu3813] [LOJ2280] 写得很好的题解 \(1.\)离散化出每一块内部不互相影响的块 \(2.\)\(dp[i][j]\)为前 \(i\) 种重叠块其中有 \(j\) 这些状态的矩 ...