Hi,
I am working on a Hibernate databased created from the basis of a uml class diagram, where uml classes are tables with their attributes as columns, and the uml associations become tables with foreign keys referencing 2 (class) tables. My problem occurs when i try to delete an entry in one of the (class) tables, which is referenced by another (association) table. I get a constraintviolationexception on the foreign key of the referencing table (which is no shock really).
My question is this: What are my options with regards to handling this? I have found the cascading delete function, which is alright as a worst case, but what i am really looking for is something like setting the columns in the referencing table entries to null if the referenced entry is deleted. This is as far as i can see possible in SQL, by manipulating the foreign key constraint to have ON DELETE SET NULL. I also see that this is not possible with Hibernate (pending ticket about this).
Is there currently a fairly simple way of doing this with Hibernate (could the foreign keys perhaps be manipulated "directly" through HQL queries?)? Are there any other options to cascading the delete?
Regards,
Tobb
|