Hi all,
My objects are the following:
An abstract class Report, extended by IntermediateReport, and by FinalReport.
A FinalReport holds a collection of IntermediateReport in a unidirectional many-to-many association.
I'd like to delete all instances of FinalReport.
I focus on
HQL Delete to do it in one shot.
So at first sight the query seems quite straightforward:
Code:
Query query = getSession().createQuery("delete FinalReport");
query.executeUpdate();
Unfortunately, this code fails in a ConstraintViolationException due to the ForeignKey constraint on the association table.
Hibernate does not delete LNK_FINAL_2_INTER_REPORT table before deleting FINAL_REPORT table :(
Check stack trace and the generated sql code below.Do you know how I can achieve this?Thanks for your help.
Alexis
Hibernate version: 3.1.2
Mapping documents:Code:
<class name="Report">
<id name="id" type="long">
....
</id>
....
</class>
<union-subclass name="IntermediateReport"
extends="Report"
table="INTER_REPORT">
....
</union-subclass>
<union-subclass name="FinalReport"
extends="Report"
table="FINAL_REPORT">
....
<set name="intermediateReportSet"
table="LNK_FINAL_2_INTER_REPORT"
lazy="true">
<key column="FINAL_ID"/>
<many-to-many class="IntermediateReport" column="INTER_ID"/>
</set>
</union-subclass>
Full stack trace of any exception that occurs:
Caused by: com.sybase.jdbc2.jdbc.SybSQLException: Dependent foreign key constraint violation in a referential integrity constraint. dbname = 'TEST', table name = 'MSP_FINAL_REPORT', constraint name = 'FK97E93DB82C3B473'.
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2429)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1865)
The generated SQL (show_sql=true):
delete from MSP_FINAL_REPORT