有两张表 Type 和 content
Type表有外键指向自己,意味着父类别和子类别
content表与Type表多对一
****************************************
type.hbm.xml
<class
name="com.arvato.cms.model.Type"
table="SUBSCRIPTION_TYPE"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="SUBSCRIPTION_TYPE"
</meta>
<meta attribute="implement-equals" inherit="false">true</meta>
<id
name="id"
type="java.lang.Long"
column="ID"
>
<meta attribute="use-in-equals">true</meta>
<generator class="native" />
</id>
<many-to-one
name="type"
class="com.arvato.cms.model.type"
>
<meta attribute="use-in-equals">true</meta>
<column name="PARENT" />
</many-to-one>
<set
name="types"
lazy="false"
inverse="false"
cascade="all-delete-orphan"
>
<key>
<column name="PARENT" />
</key>
<one-to-many
class="com.arvato.cms.model.type"
/>
</set>
<set
name="contents"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
>
<key>
<column name="SUB_TYPE_ID" />
</key>
<one-to-many
class="com.arvato.cms.model.Content"
/>
</set>
******************************************
content.hbm.xml
<id name="id" type="java.lang.Long" column="ID">
<meta attribute="field-description">
@hibernate.id generator-class="native"
type="java.lang.Long" column="ID"
</meta>
<meta attribute="use-in-equals">true</meta>
<generator class="native" />
</id>
<many-to-one name="type"
class="com.arvato.cms.model.Type"
not-null="true"
>
<meta attribute="use-in-equals">true</meta>
<meta attribute="field-description">
@hibernate.many-to-one not-null="true" @hibernate.column
name="SUB_TYPE_ID"
</meta>
<column name="SUB_TYPE_ID" />
</many-to-one>
*******************************
现在问题是:
试验一:
type1,下面有一个content1,删除type1以后,content1也被自动删除,成功
试验二:
type2(为一个父类),下面有一个type21(为该父类子类),删除type2以后,type21也被自动删除,成功
试验三:
type3(为一个父类),下面有type31(为该父类子类),下面有一个content311,删除type3以后,type31和content311也被自动删除成功,但是删除type31,却不行,
报错:
deleted object would be re-saved by cascade (remove deleted object from associations)
求解:送分100
------解决方案--------------------