tenwit wrote:
I'm speculating here, because you haven't posted your mapping.
If a child may have multiple parents then you've got a many-to-many. So long as deleting the child also deletes the relevant rows in the parent-to-child join table, then the same stuff applies. In fact, it will always apply, the only thing that might change is that deleting the child might fail if it doesn't also delete the rows in the join table. This will be the case if you've set up your mapping without inverse="true" on the parent set mapping, which obviously you must have because otherwise there would be no way to create the rows in that table.
I have not included the mapping since I was not sure how to go about this.
In the meantime, I experimented a bit and found that given the following
mapping:
Code:
<class name="events.Parent" table="PARENTS">
<id name="id" column="PARENT_ID">
<generator class="native"/>
</id>
<property name="name"/>
<set name="children" table="PARENT_CHILDREN" cascade="save-update">
<key column="PARENT_ID"/>
<many-to-many column="CHILD_ID" class="events.Child"/>
</set>
</class>
<class name="events.Child" table="CHILDREN">
<id name="id" column="CHILD_ID">
<generator class="native"/>
</id>
<property name="name" />
</class>
a child can be added to the parent and Hibernate will issue all the
necessary SQL requests. However, in order to remove a child, I have
to explicitly remove it from the parent first and then delete it.
This is what I was trying to avoid, since at the point of deleting the child,
I have no direct reference to the parent, and I cannot get Hibernate
to detect (using its model meta data) that the child is a member of some
parent children's collection and then remove the entry automatically.
Futhermore, if the inverse=true is set in the mapping of children, then
Hibernate assumes that the child manages the relationship, which it isn't,
in my case at least.
I think I have to conclude that what I'm trying to accomplish is not
possible and I have to do some of this work myself...
I'd appreciate this if you could confirm and I can vote this issue...