今天報了這個異常,這是頁面報的spring
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.數據庫
控制檯報 app
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`)ide
channel對象自關聯url
<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
緣由是 hibernate級聯刪除問題。對象
<many-to-one name="parent" column="pid" cascade="all" class="Channel"/> 這裏設置了all ,應該設置成none不進行級聯操做generator
,這個和數據庫仍是有區別string
數據庫外鍵檢查。通常狀況是,當你刪除父鍵時,不讓刪除,由於有子鍵引用這個父建id,可是hibernate的級聯不同。刪除子鍵也不行 ,因此取消級聯it