Hibernate version: 2.1.6
We're using hibernate to persist an entity with the following mapping:
Code:
<hibernate-mapping>
<class name="com.mycompany.Project" table="Projects">
<id name="id" column="id" type="java.lang.Long">
<generator class="increment"/>
</id>
<many-to-one name="defaultView" class="com.mycompany.View" column="DefaultViewId"/>
<property name="projectId" type="java.lang.Long" column="ProjectId"/>
<list name="views" table="ProjectViews" cascade="all-delete-orphan">
<key column="ProjectId"/>
<index column="ViewSequence"/>
<many-to-many class="com.mycompany.View" column="ViewId"/>
</list>
</class>
</hibernate-mapping>
During normal application operation, instances of the Project object are obtained from Hibernate, then serialized and sent to a client application where they are deserialized, viewed/changed, reserialized, and sent back to the server application for storage via Hibernate.
On the client side, the Project's list of Views list may be replaced by a new ArrayList of Views.
When a Project is retrieved from Hibernate, sent to the client app, and returned to Hibernate we receive the exception:
You may not dereference a collection with cascade="all-delete-orphan"
To me this means that since we're mapping a Project's Views as cascade all-delete-orphan, Hibernate expects certain behavior with respect to that collection. Can someone help me understand why we're getting this exception and how we can circumvent it? Is our only option to use a different cascade strategy and manually delete the orphaned Project Views?
Thanks!
-Alex