Hibernate级联删除

如果cascade属性是默认值"none",当hibernate删除一个持久化对象的时候,不会自动删除与它关联的其他持久化对象。如果希望自动删除它关联的其他持久化对象,可以把casacde属性设为"delete";

 

<set

	name="students"

	cascade="delete"

	inverse="true">

	<key column="school_id"/>

	<one-to-many class="Student"/>

</set>


那么hibernate在删除一个Shool对象时,实际执行的SQL是:

 

 

delete from students where school_id =1;

delete from school where id=1;


 

你可能感兴趣的:(Hibernate)