我有三张表分别为表A,B,C。表B和表C是表A的子表,表C是表B的子表。现在我要在删除表A的同时删除表B和表C。以下是表A的配置文件:
<id name="bill" type="java.lang.String">
<column name="BILL" length="12" />
<generator class="assigned" />
</id>
<set name="capDeliverscatDs" cascade="all" lazy="false" inverse="false">
<key>
<column name="BILL" length="12" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapDeliverscatD" />
</set>
<set name="capAcceptscatThirds" cascade="all" lazy="false" inverse="false">
<key>
<column name="BILL" length="12" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapAcceptscatThird" />
</set>
以下是表B的配置文件:
<id name="orderid" type="java.lang.String">
<column name="ORDERID" />
<generator class="assigned" />
</id>
<many-to-one name="capDeliverscatH" lazy="false" class="com.cap.entity.CapDeliverscatH" fetch="select">
<column name="BILL" length="12" not-null="true" />
</many-to-one>
<set name="capAcceptscatThirds" cascade="all" lazy="false" inverse="true">
<key>
<column name="ORDERID" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapAcceptscatThird" />
</set>
以下是表C的配置文件:
<id name="itemid" type="java.lang.String">
<column name="ITEMID" length="3" />
<generator class="assigned" />
</id>
<many-to-one name="capDeliverscatH" lazy="false" class="com.cap.entity.CapDeliverscatH" fetch="select">
<column name="BILL" length="12" not-null="true" />
</many-to-one>
<many-to-one name="capDeliverscatD" lazy="false" class="com.cap.entity.CapDeliverscatD" fetch="select">
<column name="ORDERID" not-null="true" />
</many-to-one>
为什么我删不掉这三张表??求高手赐教。 在线等......
<id name="bill" type="java.lang.String">
<column name="BILL" length="12" />
<generator class="assigned" />
</id>
<set name="capDeliverscatDs" cascade="all" lazy="false" inverse="false">
<key>
<column name="BILL" length="12" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapDeliverscatD" />
</set>
<set name="capAcceptscatThirds" cascade="all" lazy="false" inverse="false">
<key>
<column name="BILL" length="12" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapAcceptscatThird" />
</set>
以下是表B的配置文件:
<id name="orderid" type="java.lang.String">
<column name="ORDERID" />
<generator class="assigned" />
</id>
<many-to-one name="capDeliverscatH" lazy="false" class="com.cap.entity.CapDeliverscatH" fetch="select">
<column name="BILL" length="12" not-null="true" />
</many-to-one>
<set name="capAcceptscatThirds" cascade="all" lazy="false" inverse="true">
<key>
<column name="ORDERID" not-null="true" />
</key>
<one-to-many class="com.cap.entity.CapAcceptscatThird" />
</set>
以下是表C的配置文件:
<id name="itemid" type="java.lang.String">
<column name="ITEMID" length="3" />
<generator class="assigned" />
</id>
<many-to-one name="capDeliverscatH" lazy="false" class="com.cap.entity.CapDeliverscatH" fetch="select">
<column name="BILL" length="12" not-null="true" />
</many-to-one>
<many-to-one name="capDeliverscatD" lazy="false" class="com.cap.entity.CapDeliverscatD" fetch="select">
<column name="ORDERID" not-null="true" />
</many-to-one>
为什么我删不掉这三张表??求高手赐教。 在线等......
一直报这个错:
org.springframework.dao.DataIntegrityViolationException: could not delete: [com.cap.entity.CapDeliverscatH#eo_0001]; nested exception is org.hibernate.exception.ConstraintViolationException: could not delete: [com.cap.entity.CapDeliverscatH#eo_0001]Caused by: org.hibernate.exception.ConstraintViolationException: could not delete: [com.cap.entity.CapDeliverscatH#eo_0001]Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: DELETE 语句与 REFERENCE 约束"FK_CAP_DELIVERSCAT_D_CAP_DELIVERSCAT_H"冲突。该冲突发生于数据库"capdb",表"dbo.CAP_DELIVERSCAT_D", column 'BILL'。
不知道sqlserver有没有deferrable约束,使数据库延时到commit时再去检查完整性约束
默认的immediate会在sql语句处理之后就进行完整性约束的检查...
hibernate的相关文档肯定有介绍的