在更新用户时,将通过级联(从关联中删除已删除的对象)重新保存已删除的对象

时间:2013-09-27 06:53:02

标签: java hibernate nhibernate hibernate-mapping

休眠映射:

User.hbm.xml

<hibernate-mapping package="com.user">
  <class name="User" lazy="true" table="USER">
<set name="StudentOrganizations" inverse="true" cascade="all-delete-orphan"    fetch="select" sort="natural">
<key>
<column name="STUDENT_ID" not-null="true" />
    </key>
<one-to-many class="com.StudentOrganization" />
</set>
</class>



StudentOrganization.hbm.xml

<hibernate-mapping>
 <class name="com.StudentOrganization" table="USER_ORGANIZATION">
 <cache usage="read-write" />
   <many-to-one name="user" class="com.User" update="false" insert="false" fetch="select">
<column name="STUDENT_ID" not-null="true" />
   </many-to-one>
   <many-to-one name="organization" class="com.Organization" update="false" insert="false" fetch="select">
  <column name="ORGANIZATION_ID" not-null="true" />
   </many-to-one>
 </class>
 </hibernate-mapping><BR>

更新学生记录时的伪代码。

myDAO.detach(myOldDetails);
myDAO.merge(aResource);

在更新学生详细信息时,我收到错误 "deleted object would be re-saved by cascade (remove deleted object from associations): [com.StudentOrganization]....."

1 个答案:

答案 0 :(得分:0)

这是一个类似的question

希望..添加fetchType = lazy将解决您的问题。