Hibernate version: 3.2.1
Name and version of the database you are using: Oracle 10g
I have a parent-child relationship modeled as follows:
The parent class:
Code:
<class
name="Model"
table="MODEL"
>
<meta attribute="sync-DAO">false</meta>
<id
name="id"
type="integer"
column="MODEL_ID"
>
<generator class="sequence">
<param name="sequence">model_seq</param>
</generator>
</id>
<property
name="modelName"
column="MODEL_NAME"
type="string"
not-null="true"
length="64"
/>
<property
name="createDate"
column="CREATE_DATE"
type="date"
not-null="false"
length="7"
/>
<many-to-one
name="project"
column="PROJECT_NAME"
class="Project"
fetch="join"
not-null="true"
>
</many-to-one>
<set name="modelDetails" cascade="all,delete-orphan">
<key column="MODEL_ID"/>
<one-to-many class="ModelDetail"/>
</set>
</class>
The child class:
Code:
<class
name="ModelDetail"
table="MODEL_DTL"
>
<meta attribute="sync-DAO">false</meta>
<composite-id name="id" class="ModelDetailPK">
<key-many-to-one
name="model"
class="Model"
column="MODEL_ID"
/>
<key-many-to-one
name="costCode"
class="CostCode"
column="COST_CODE_ID"
/>
<key-many-to-one
name="optionCode"
class="OptionCode"
column="OPTION_CODE_ID"
/>
<key-property column="QUOTE_NBR" name="quoteNbr" type="integer"/>
<key-property column="STORE_NBR" name="storeNbr" type="integer"/>
</composite-id>
<property
name="costFactor"
column="COST_FACTOR"
type="string"
not-null="true"
length="1"
/>
<property
name="activeFlag"
column="ACTIVE_FLAG"
type="yes_no"
not-null="true"
length="1"
/>
<property
name="lastUpdateDate"
column="LAST_UPDATE_DATE"
type="date"
not-null="false"
length="7"
/>
<property
name="createDate"
column="CREATE_DATE"
type="date"
not-null="false"
length="7"
/>
</class>
The problem is that when I do a delete on a Model that has a single ModelDetail in its set, an update on the ModelDetail (set MODEL_ID = null) is attempted, which causes a database error.
Code:
Hibernate: update MODEL_DTL set MODEL_ID=null where MODEL_ID=?
2008-04-21 13:21:19,554 [main] WARN - SQL Error: 1407, SQLState: 72000
2008-04-21 13:21:19,554 [main] ERROR - ORA-01407: cannot update ("QMS"."MODEL_DTL"."MODEL_ID") to NULL
2008-04-21 13:21:19,554 [main] WARN - SQL Error: 1407, SQLState: 72000
2008-04-21 13:21:19,554 [main] ERROR - ORA-01407: cannot update ("QMS"."MODEL_DTL"."MODEL_ID") to NULL
I have tried several different O/R mapping strategies to get this working properly (including inverse many-to-one and iterating through the details, deleting each one individually before deleting the model), but have had no success. I have seen this work in simpler relational schemas where the child object does not possess a composite-id PK structure, but I'm confounded by what is happening here.
Are there any recommendations or different mapping strategies I might try that would make hibernate cascade the delete?