We have a child collection which is mapped as a one-to-many List:
Code:
<list name="children"
table="CHILDREN"
lazy="true"
cascade="all-delete-orphan">
<key column="parent_id"/>
<index column="I"/>
<one-to-many class="Child"/>
</list>
The Child entity has a many-to-one reference to the Parent entity and has a not-null value set to true. We are aware that when using Lists, a mandatory requirement for this collection because the index is important to our domain, you cannot use inverse relationships.
We have read the parent/child documentation and have applied in many other areas with success. However, currently we are experiencing deletion issues when trying to remove all the collections, which is of type List, from the parent.
Currently, we are doing it in this way:
Code:
...
p.getChildren().remove(child);
session.delete(child);
...
We have a foreign key constraint on the child table to the parent table.
Our exception upon deletion is:
Code:
java.sql.SQLException: Cannot insert the value NULL into column... column does not allow nulls
As already mentioned we are using a List and we are aware we cannot use inverse="true". Also, we have attempted setting cascade="all-delete-orphan" without any success. In fact, it produces the same error message.
Question
Our use case requires that we be able to delete this collection of children. Can anyone see any glaring issues with the way we are attempting to delete collections?
We have tried several different mapping and deletion idioms suggested in this forum and in the ref documentation.
Additional Information
Hibernate 2.1.3
MS SQL Server 2000
New Atlanta JTurbo Driver 0.7.1
Cheers,
Roll