Hi,
I am using Hibernate 3.0b4
I have an author and a book class with a many-to-many association between them.
In the author mapping file my 'books'-set has cascade=none. In the book mapping file my 'authors'-set has cascade=delete. With these settings I thought I would achieve the following:
*) when I delete a book, the corresponding relation with author will be deleted automatically by hibernate
*) when I delete an author, the delete should fail if the author is still associated with any books. So hibernate does not delete the relation with book.
The problem is that when I delete an author using session.delete(author) the corresponding entries from the table 'BOOK_AUTHOR' are deleted as well. So the cascade=none setting doest not seem to have any effect.
I am still pretty new to hibernate and I am used to trust on the relational integrity rules from by database to make sure my application will not delete any data that should not be deleted. So Hibernate actually does too good a job for me, because it weakens my referential integrity rules.
Is there a way to prevent hibernate to cascade-delete at one side of a many-to-many relation and to allow the cascade-delete on the other side of the relation and if so, how could I achieve this? Am I doing something wrong?
Thanks a lot.
Luc Feys
|