I have a problem with deleting an object with Hibernate. The mapping is this:
Class Report
Code:
<class name="Report" table="report">
<id name="id" type="long" unsaved-value="0">
<column name="report_id" sql-type="integer" not-null="true"/>
<generator class="native"/>
</id>
<property name="folderCreated" not-null="true" />
<property name="draftDeadline" not-null="false" />
<property name="finalDeadline" not-null="false" />
<many-to-one name="treeNode" cascade="none" lazy="false" class="TreeNode" />
</class>
Class M3ItemCode:
<joined-subclass name="M3Item" extends="Item" table="item_m3">
<key column="item_id"/>
<property name="type" not-null="true" />
<property name="specificType" not-null="false" />
<set name="reports" inverse="false" cascade="all" table="item_m3_reports">
<key column="item_id"/>
<many-to-many unique="true" column="report_id" class="Report"/>
</set>
<property name="identifier"/>
<property name="startDate"/>
<property name="endDate"/>
<property name="itemNumber" not-null="true"/>
<property name="duration" not-null="true" />
<property name="deadlineProtocol"/>
<property name="laboratories"/>
<property name="CRO"/>
<property name="createFolder" not-null="true" />
</joined-subclass>
When I try to delete a Report using:
Code:
tx = getCurrentSession().beginTransaction();
getCurrentSession().delete(object);
commitTransaction(tx);
Hibernate starts by executing the following SQL:
delete from report where report_id=?
This causes a ConstraintViolation. Which isn't so strange as a row has to be removed from the join table (item_m3_reports) first. How can i make sure that the row from the join table is deleted first?