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

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. delphi计算两个时间差

    uses DateUtils; var S1, S2: string; T1, T2: TDateTime; D, H, M, S: Integer; Value: Int64; begin S1 : ...

  2. switch case 判断是否为按钮、设置属性 Load Foreach 绑定事件

    private void button9_Click(object sender, EventArgs e) { foreach (Control CT in this.Controls) {//判断 ...

  3. javascript ie8兼容 a标签href javascript:void(0);

    ie8兼容 a标签href javascript:void(0); 尽量不要用javascript:协议做为A的href属性,这样不仅会导致不必要的触发window.onbeforeunload事件;

  4. 001.linux的基础优化(期中架构方面的优化)

    1. linux内核优化 第一步 cat >>/etc/sysctl.conf<<EOF net.ipv4.tcp_fin_timeout = 2 net.ipv4.tcp_t ...

  5. Promise超时情况

    export const ERROR_PROMISE_TIMEOUT = 'ERROR_PROMISE_TIMEOUT'; export default function (promise, time ...

  6. 【bzoj4869】[Shoi2017]相逢是问候 线段树+扩展欧拉定理

    Description Informatikverbindetdichundmich. 信息将你我连结.B君希望以维护一个长度为n的数组,这个数组的下标为从1到n的正整数.一共有m个操作,可以 分为两 ...

  7. Ubuntu16.04搭建各种开发环境的IDE: QT5 , CodeBlocks ,eclipse-cdt, PyCharm

    搭建Ubuntu下C/C++以及Python的集成开发环境,采用双系统(Win7+Ubuntu)的Ubuntu16.04-LTS系统, 关于双系统的搭建可以参考下面博客(图文十分详细):https:/ ...

  8. 'javac' 不是内部或外部命令,也不是可运行的程序

    win10 系统下'javac' 不是内部或外部命令,也不是可运行的程序 1.在系统变量下面配置 JAVA_HOME:你自己的jdk的路径 CLASSPATH= .;%JAVA_HOME%libdt. ...

  9. 剩下的树 THU 机试

    链接:https://www.nowcoder.com/questionTerminal/f5787c69f5cf41499ba4706bc93700a2来源:牛客网 有一个长度为整数L(1<= ...

  10. Exalogic 物理连线

    以上图表为Exalogic 1/8配中的思科交换机连线,而1/4配.半配.满配的内置思科交换机连线基本上与以上图表一致.下面对该图表进行简要说明: (1).每台计算节点,只需要从net0上连接一根线到 ...