While I've been using Hibernate for several months now, I still occasionally stumble upon things that I've fundamentally misunderstood with regards to this tool, so I wanted to confirm that I'm correctly handling entity deletion in my system.
I have an entity, QuestionGroup that is associated with a number of other entities in my system.
- It is a child (in a many-to-many relationship) of Assessment
- It has a many-to-one relationship with QuestionGroupAttempt
- It is a parent of multiple Question entities
- etc.
I believe that I have a fairly good handle on how to properly remove a QuestionGroup and it's child Question objects. This is covered quite thoroughly in "Section 8: Parent Child Relationships" in the Hibernate Documentation.
What I'm curious about is how deletions should be handled with regards tot he other relationships that QuestionGroup is a part of. Perhaps I'm being naive, but it seems that Hibernate is aware of the relationships that exist between QuestionGroup and Assessment, for instance, and that if I were to remove a QuestionGroup which belonged to an Assessment, Hibernate would know to remove the relationship between these two entities. The same would seem true for the many-to-one relationship with QuestionGroupAttempt.
However, what I'm finding is that in order to avoid a foreign key violation when deleting a [i]QuestionGroup[i], I need to remove these relationships manually. That's ok. It's a little extra work that I wasn't expecting, but I really don't have a problem with that. However, I wanted to make sure, by asking here, that I wasn't missing something obvious to make this all a little more transparent.
Thanks!
-Matt
|