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
|