-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cascaded delete causes violation of foreign key constraint
PostPosted: Thu Jul 08, 2010 11:44 am 
Newbie

Joined: Thu Jul 08, 2010 11:24 am
Posts: 2
Hi all,
I recently tried to migrate databases and update Hibernate to a newer version, but this is giving me some trouble when it comes to cascaded deletes.
Our database contains some surveys. These surveys each have a number of mailings, and these mailings contain Informations, which are basically String containers for multiple translations of the same piece of text.

The relevant mappings are:

SurveyDefinition.hbm.xml:
Code:
...
<set name="mailings" inverse="true" cascade="evict, delete">
   <key column="surveyDefinition" on-delete="cascade"/>
   <one-to-many class="Mailing" />
</set>
...


Mailing.hbm.xml:
Code:
...
<many-to-one name="content" class="Information" not-null="true" unique="true" cascade="all" />
<many-to-one name="subject" class="Information" not-null="true" unique="true" cascade="all" />
...


Information.hbm.xml:
Code:
...
<id name="id" column="id">
   <generator class="native" />
</id>
...


Now, when deleting a survey, it should also delete all its mailings and all Informations belonging to these mailings. This used to happen just fine when using MySQL 5 in combination with Hibernate 3.3.2.GA. However, when migrating to PostgreSQL and/or upgrading to Hibernate 3.5.1-Final (all three of these other combinations fail!), I get a foreign key constraint violation when deleting the surveyDefinition. When I delete a mailing manually everything works just fine.

The exact error:
Code:
ERROR - JDBCExceptionReporter      - ERROR: update or delete on table "information" violates foreign key constraint "fk3471b287f8128fb" on table "mailings"
  Detail: Key (id)=(26) is still referenced from table "mailings".


The details of this constraint according to pgAdmin:
Code:
-- Foreign Key: fk3471b287f8128fb

-- ALTER TABLE mailings DROP CONSTRAINT fk3471b287f8128fb;

ALTER TABLE mailings
  ADD CONSTRAINT fk3471b287f8128fb FOREIGN KEY ("content")
      REFERENCES information (id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;


The same problem occurs with other similar cascaded deletes. To me it seems that somehow Hibernate deletes things from the database in the wrong order, and not as a single transaction but in separate queries.
Can anyone shed any light on what I'm doing wrong? :) Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Cascaded delete causes violation of foreign key constraint
PostPosted: Tue Aug 17, 2010 4:49 am 
Newbie

Joined: Thu Jul 08, 2010 11:24 am
Posts: 2
*bump*
Can no one shed any light on this? I am at a complete loss.. Upgraded to 3.5.4-Final now, but the same problem remains.


Top
 Profile  
 
 Post subject: Re: Cascaded delete causes violation of foreign key constraint
PostPosted: Thu Jul 28, 2011 10:49 am 
Newbie

Joined: Thu Jul 28, 2011 10:47 am
Posts: 1
I am having the same issue. Any luck on this? Any help?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.