zoukankan      html  css  js  c++  java
  • 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的级联不一样。删除子键也不行 ,所以取消级联

  • 相关阅读:
    数字货币资金费策略
    如何利用CCXT交易数字货币合约
    三分钟玩转微软AI量化投资开源库QLib
    商品期货月度效应的统计
    数字货币无风险收益率又双叒叕扩大了!
    Omega System Trading and Development Club内部分享策略Easylanguage源码 (第二期)
    【mac】安装配置 homebrew, Nginx
    【Typescript+Vue】01. easy
    【python】sudo python -m SimpleHTTPServer
    【windows】docker to vmware
  • 原文地址:https://www.cnblogs.com/or2-/p/3539823.html
Copyright © 2011-2022 走看看