-->
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.  [ 4 posts ] 
Author Message
 Post subject: cascade delete help please
PostPosted: Mon May 03, 2004 10:53 pm 
Newbie

Joined: Thu Mar 25, 2004 4:09 pm
Posts: 6
I've got an infoset which contains a set of infosetDocuments:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.potomacfusion.vid.dao.Infoset"
table="infoset"
>
<meta attribute="generated-class">com.potomacfusion.vid.dao.InfosetDTO</meta>
<id name="id" type="string" unsaved-value="null" >
<column name="infoset_id" sql-type="char(32)"
not-null="true"/>
<generator class="uuid.hex"/>
</id>


<property
name="infosetName"
type="java.lang.String"
column="infoset_name"
length="255"
/>
<property
name="graphData"
type="java.lang.String"
column="graph_data"
length="2147483647"
/>

<!-- associations -->
<one-to-one name="query"
class="com.potomacfusion.vid.dao.Query" property-ref="infoset">
</one-to-one>
<set name="infosetDocuments" table="infoset_document_assn" inverse="true" cascade="all">
<key column="infoset_id" />
<one-to-many class="com.potomacfusion.vid.dao.InfosetDocumentAssn" />
</set>

</class>
</hibernate-mapping>

InfosetDocument relate a documents to multiple infosets:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class
name="com.potomacfusion.vid.dao.InfosetDocumentAssn"
table="infoset_document_assn"
>
<meta attribute="generated-class">com.potomacfusion.vid.dao.InfosetDocumentAssnDTO</meta>
<!-- A 32 hex character is our surrogate key. It's automatically
generated by Hibernate with the UUID pattern. -->
<id name="id" type="string" unsaved-value="null" >
<column name="id" sql-type="char(32)" not-null="true"/>
<generator class="uuid.hex"/>
</id>

<property name="infosetId" type="java.lang.String" insert="false" update="false">
<column name="infoset_id" sql-type="char(32)" not-null="true"/>
</property>

<property name="documentId" type="java.lang.String" insert="false" update="false">
<column name="document_id" sql-type="char(32)" not-null="true"/>
</property>


<!-- associations -->
<many-to-one name="infoset" column="infoset_id" class="com.potomacfusion.vid.dao.Infoset"/>

<many-to-one name="document" column="document_id" class="com.potomacfusion.vid.dao.Document" cascade="save-update"/>

</class>
</hibernate-mapping>

When I try and delete an infoset I see the follow:

Hibernate: delete from infoset_document_assn where id=?
Hibernate: delete from infoset where infoset_id=?
WARN [21:32:55] (JDBCExceptionReporter.java:38) - SQL Error: 1217, SQLState: S1000
ERROR [21:32:55] (JDBCExceptionReporter.java:46) - General error, message from server: "Cannot delete or update a parent row: a foreign key constraint fails"

The problem seems to be that the delete from infoset_document_assn is using the wrong key 'id' instead of what I thought it should 'infoset_id' as configured in the infosetDocuments 'set' element. Can anyone help me understand what I've done wrong and how I can fix it?

Thanks
Ted


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 4:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Use different columns for
<id>
and <set><key>
in Infoset
These are unrelated.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 11:10 am 
Newbie

Joined: Thu Mar 25, 2004 4:09 pm
Posts: 6
I'm sorry I don't understand what exactly you are suggesting I should do or why. Are you suggesting that I change the column name of the primay key in the infoset table? The key column attribute represents the foreign key in the related table (infoset_document_assn) right? So why would it matter if it has the same name as the primary key in the infoset table?

How does Hibernate know which column to use in the 'delete from infoset_document_assn' where clause, does it not use the sets key element to define this?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 12:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
forget what I've said, its all crap.
Check the debug logs to understand what's happening

_________________
Emmanuel


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