I am trying to delete a property from my parent object which has a one-to-one relationship to the property, but unfortunately, hibernate doesn't let me set cascade="all-delete-orphan" for a one-to-one mapped property.
The save of a new property and update of an existing property is working great, however, the behaviour that I'm looking for and missing is that I want the propertydata row to be deleted from the database for a given user's property if the following were executed. Simply setting the ObjectProperty.value to null wouldn't suffice because the legacy database has a non-null constraint on that column that has to stay there for our other apps to work. Any suggestions to easily resolve this?
myUserEntity.setFirstNameProperty(null);
sess.update(myUserEntity);
<class name="UserEntity"
entity-name="User"
schema="myschema"
table="users">
<id name="id" type="java.lang.Integer">
<column name="objectid"/>
<generator class="assigned"/>
</id>
<one-to-one name="firstNameProperty" entity-name="ObjectProperty" cascade="all">
<formula>objectid</formula>
<formula>1</formula>
<formula>0</formula>
<formula>23</formula>
</one-to-one>
</class>
<class name="ObjectPropertyEntity"
entity-name="ObjectProperty"
schema="myschema"
table="propertydata">
<composite-id>
<key-property name="objectid" column="objectid" type="java.lang.Integer"/>
<key-property name="classid" column="classid" type="java.lang.Integer"/>
<key-property name="pageid" column="pageid" type="java.lang.Integer"/>
<key-property name="propertyid" column="propertyid" type="java.lang.Integer"/>
</composite-id>
<property name="value" column="value" type="java.lang.String" length="255"/>
</class>
|