我有几个Hibernate映射文件,其中包含指向其他对象的多对多和多对一组。我正在尝试实现可以删除对象的后台办公方案,但我经常遇到java.sql.SQLIntegrityConstraintViolationException ...违反外键...该语句已被回滚。
我想知道删除这些条目需要做些什么。这是我的一个XML映射文件的示例
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.floreantpos.model">
<class lazy="false" name="com.floreantpos.model.MenuItem" optimistic-lock="version" table="MENU_ITEM">
<id column="ID" name="id" type="java.lang.Integer">
<generator class="assigned"/>
</id>
<version column="MODIFIED_TIME" name="modifiedTime" type="timestamp"/>
<property column="NAME" length="30" name="name" not-null="true" type="java.lang.String"/>
<property column="PRICE" length="52" name="price" not-null="true" type="java.lang.Double"/>
<property column="PLU" length="6" name="plu" not-null="false" type="java.lang.Integer"/>
<property column="VIEW_ORDER_VALUE" name="viewOrderValue" type="java.lang.Integer"/>
<property column="BUTTON_COLOR" name="buttonColor" type="java.lang.Integer"/>
<property column="NEXT_SCREEN" length="30" name="nextScreen" type="java.lang.String"/>
<property column="VISIBLE" name="visible" type="java.lang.Boolean">
<meta attribute="defaultValue">true</meta>
</property>
<!-- uni-directional many-to-one association to FoodGroup -->
<many-to-one class="com.floreantpos.model.MenuGroup" name="parent">
<column name="GROUP_ID"/>
</many-to-one>
<list cascade="all" inverse="false" lazy="true" name="shifts" table="MENUITEM_SHIFT">
<key column="MENUITEM_ID"/>
<list-index column="SHIFT_ORDER"/>
<one-to-many class="MenuItemShift"/>
</list>
<list cascade="all" inverse="false" lazy="true" name="menuItemModiferGroups">
<key column="MENUITEM_MODIFIERGROUP_ID"/>
<list-index column="GR_ORDER"/>
<one-to-many class="MenuItemModifierGroup"/>
</list>
<!-- uni-directional many-to-one association to Tax -->
<many-to-one class="com.floreantpos.model.Tax" lazy="false" name="tax">
<column name="TAX_ID"/>
</many-to-one>
<set cascade="all" lazy="false" name="menuItemModifiers" table="MENUITEM_MENUMODIFIERS">
<key column="MENU_ITEM_ID"/>
<many-to-many class="com.floreantpos.model.MenuModifier" column="MENU_MODIFIER_ID"/>
</set>
</class>
</hibernate-mapping>
我见过有关@OnDelete(...)注释的帖子,但这似乎不适合xml映射方案。在删除方法中,我正在循环遍历包含外键约束的任何集合并删除每个单独的对象,但我仍然没有很少的运气删除。