I'm starting to loose my hair due to the following problem...
I am using Hibernate 3.2.2.
I have a class with an array of key-value pairs:
Code:
<class name="SomeClass" table="someclass">
<id name="layerID" column="id" access="field">
<generator class="native"/>
</id>
<array name="params" access="field" cascade="all-delete-orphan">
<key column="params"/>
<index column="idx"/>
<one-to-many class="KeyValue"/>
</array>
</class>
The KeyValue-Class just contains two strings.
Code:
<class name="KeyValue" table="parameters">
<id type="int" column="id">
<generator class="native"/>
</id>
<property name="key" access="field" length="32" not-null="true"/>
<property name="value" access="field" length="128"/>
</class>
As long as I just write or read SomeClass-objects from/to the database everything is fine.
But when I delete an object, the elements of the array are orphaned but stay in the database.
I have tried almost every possible combination of cascade options (all, delete, all-delete-orphan, etc) and key-settings but I just can not convince Hibernate to delete the elements of the array.
Sure, I could delete any orphaned KeyValue-element manually with an additional SQL/HQL-statement - but I think that is not the way it's meant to be...
Since this is one of the basic features of a database (on delete="cascade" with an foreign key) I'm sure that there is a solution within Hibernate.
But I can not find any valuable information in the Hibernate documentation, so I hope that anyone can give me a hint how to solve this problem.
Thank's in advance,
-Marc-