-->
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: How to automatically delete orphaned many-to-one association
PostPosted: Wed Feb 27, 2008 4:24 pm 
Newbie

Joined: Wed Feb 27, 2008 4:04 pm
Posts: 1
Hibernate 3.2.5
MySQL 5.0


<many-to-one
name="documentReference" cascade="all"
class="DocumentReference"
column="DOCUMENT_REFERENCE_ID"
unique="true"
fetch="join"/>


I have a class which has a DocumentReference, as per above mapping snippet. Two classes actually have the above mapping since two classes have a DocumentReference.

Everything works correctly, except that when my object has a valid documentReference, and that I 'setDocumentReference(null)', the DOCUMENT_REFERENCE_ID column becomes null (as expected), but the corresponding row in my DOCUMENT_REFERENCE table is not deleted, it's just gets 'orphaned'. I was expecting (hoping?) it would also get deleted.

I don't believe I can use a one-to-one mapping using a shared primary key association since there are two 'parent' classes, which I believe is a problem for the foreign id generator.

There is no error, no stack trace, just the null column in one table and the 'orphaned' row in the DOCUMENT_REFERENCE table.

Is there a way to achieve the automatic deletion of the row? Is there any alternative or do I just need to use session.delete(documentReference) in addition to setDocumentReference(null)?

Thanks for your help,
Eric


Top
 Profile  
 
 Post subject: Re: How to automatically delete orphaned many-to-one associa
PostPosted: Wed Feb 27, 2008 4:46 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I have a few reasons in mind why this should not work with DELETE_ORPHAN and your best shot might be to do it manually with is really a trivial task.


Farzad-


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.