配置文件代码
<class name="com.et.pojo.BigType" table="tb_bigtype">
<id name="id" type="java.lang.Integer">
<column name="id"/>
<generator class="increment"/>
</id>
<property name="bigName" type="java.lang.String">
<column name="bigName"/>
</property>
<property name="createTime" type="java.sql.Date">
<column name="createTime"/>
</property>
<set name="smallTypes" inverse="true" cascade="all" lazy="false">
<key column="bigId"></key>
<one-to-many class="com.et.pojo.SmallType"/>
</set>
</class>加了cascade=“all”,还是无法级联进行删除,提示外键问题,Cannot delete or update a parent row: a foreign key constraint fails,烦请高手帮忙Hibernate
<class name="com.et.pojo.BigType" table="tb_bigtype">
<id name="id" type="java.lang.Integer">
<column name="id"/>
<generator class="increment"/>
</id>
<property name="bigName" type="java.lang.String">
<column name="bigName"/>
</property>
<property name="createTime" type="java.sql.Date">
<column name="createTime"/>
</property>
<set name="smallTypes" inverse="true" cascade="all" lazy="false">
<key column="bigId"></key>
<one-to-many class="com.et.pojo.SmallType"/>
</set>
</class>加了cascade=“all”,还是无法级联进行删除,提示外键问题,Cannot delete or update a parent row: a foreign key constraint fails,烦请高手帮忙Hibernate
Cascade:负责控制关联对象的级联操作,包括更新、删除等,也就是说对一个对象进行更新、删除时,其它对象也受影响,比如我删除一个对象,那么跟它是多对一关系的对象也全部被删除。
举例说明区别:删除“一”那一端一个对象O的时候,如果“多”的那一端的Inverse设为true,则把“多”的那一端所有与O相关联的对象外键清空;如果“多”的那一端的Cascade设为Delete,则把“多”的那一端所有与O相关联的对象全部删除。
alter tablename drop foreign key ...
alter tablename drop key ....
alter tablename add foreign key ... on delete cascade