These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HQL DELETE & Collections
PostPosted: Thu Mar 23, 2006 2:10 pm 
Beginner
Beginner

Joined: Thu Feb 16, 2006 9:53 am
Posts: 24
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 3:27 pm 
Beginner
Beginner

Joined: Thu Feb 16, 2006 9:53 am
Posts: 24
My answer is here:


I feel very disappointed :((


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.