-->
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: many-to-many with link table foreign key violation
PostPosted: Thu Jul 15, 2010 10:42 pm 
Newbie

Joined: Mon Mar 27, 2006 7:46 pm
Posts: 17
I have a many to many with a link table and every time i delete one of the objects i get a foreign key violation on the link table.

I am using hibernate 3, but an older version of it

Using the author/book example here is what my mappings look like:

For author:
<set name="books" table="author_book" inverse="true" cascade="save-update" >
<key>
<column name="author_id" not-null="true"/>
</key>
<many-to-many class="Book">
<column name="book_id" unique="true"/>
</many-to-many>
</set>

For book:
<set name="authors" table="author_book" inverse="false">
<key>
<column name="book_id" not-null="true"/>
</key>
<many-to-many class="Author">
<column name="author_id" unique="true"/>
</many-to-many>
</set>

My expectation is that when I delete an author the entry in the link table will be removed as well, but the book stays active.

However, when I delete an author I get a foreign key violation on the link table. I have tried countless different settings and I always get the same result.

What am i doing wrong?
thanks


Top
 Profile  
 
 Post subject: Re: many-to-many with link table foreign key violation
PostPosted: Sun Jul 18, 2010 11:02 am 
Newbie

Joined: Sun Jul 18, 2010 10:15 am
Posts: 8
EDIT:

sorry I misread the post.

first, the Hibernate reference states "It does not usually make sense to enable cascade on a <many-to-one> or <many-to-many> association. Cascade is often useful for <one-to-one> and <one-to-many> associations."

second, you have made Author the inverse of the association, so will changing Author have any effect on Book?

Have you tried removing the Author you are deleting from the Books Set before committing?


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.