假设我有两个实体,并且它们之间的双向多对多关系映射到 Hibernate。
两个类中的 xml 配置如下所示:
<hibernate-mapping>
<class name="com.example.MyEntity">
<set name="myOtherEntities" cascade="all-delete-orphan">
<key column="entity_id"/>
<many-to-many column="my_other_entity_id" class="com.example.OtherEntity" />
</set>
</class>
</hibernate-mapping>
如何仅终止它们之间的关联而不删除任何实体?
如果我clear()
设置MyEntity
并调用,Session.flush()
那么MyOtherEntity
对象将被删除,但我只想清除连接表中的记录。