Despite the highly accepted accepted answer, I have another answer to this question.
Consider a class diagram with these relationships:
Parent => list of Items
Item => Parent
No one ever said that the relation Item => Parent is redundant for the relation Parent => Items. An item can refer to any Parent.
But in your application, you know that relationships are redundant . You know that relationships do not need to be stored separately in the database. Thus, you decided to save it in one foreign key , pointing from the element to the parent. This minimal information is enough to create a list and link back.
All you have to do to match this with NH:
- use the same foreign key for both relationships
- tell NH that one (list) is redundant for the other and can be ignored when storing an object. (This is what NH actually does with
inverse="true" )
These are thoughts that are related to the opposite. Nothing more. This is not a choice; there is only one way to display it correctly.
Spy Problem : This is a completely different discussion if you want to maintain a link from an element to a parent. It depends on your business model, NH does not make any decisions in this. If one of the relations is absent, then, of course, there is no redundancy and there is no use of the opposite.
Misuse: If you use inverse = "true" in a list that does not have redundancy in memory, it just isn't saved. Unless you specify the opposite value = "true" if it should be there, NH may store redundant information twice.
Stefan Steinegger Feb 04 2018-11-11T00: 00Z
source share