Quote:
your mapping is completely broken anyway
is not very polite. If your goal is to help newbies like me, it might be more appropriate to avoid such sentences. Just say "I just noticed the usage of inverse in your mapping is wrong. Please read the documentation about it."
Actually, I don't want my child nodes to be attached to several parent nodes at the same time (this is reflected in my mapping: there is only one parent per node), so the orphan rule matches my goals. From an OO perpective, they are immutable values.
Also, your online-documentation specifically asks to use all-delete-orphans.
Since I'm new to Hibernate, I didn't know it was an ugly hack and shouldn't be used. Also, there is nothing in the documentation which hints in this direction, so how can I know?
Let's come back to the comment about misuse of inverse. Let's see the docs:
Quote:
By specifying inverse="true", we explicitly tell Hibernate which end of the association it should synchronize with the database.
(Chapter 3.7.4 Making the association bidirectional from "Hibernate in Action")
That's what I want: The parent attribute is what really exists in the database. The children collection is just virtual. I want Hibernate to propagte changes over the parent attribute.
Interestingly enough, all my test cases which add, create, delete and move children around (thanks to your input, all work now) don't care if or where I specify inverse=true.
Since the book is already one year old, I had a look in the
Online documentation from the website. Here is the example:
Code:
<set name="children" inverse="true">
<key column="parent_id"/>
<one-to-many class="Child"/>
</set>
So this means the documentation is wrong?
Or is this a special feature of list mappings? I couldn't find much about them in the docs besides that you should use them when the order of the items is important (which it is in my case).