According to nHibernate profiler, I need to add inverse="true" to my mapping file, however, I can't seem to find examples on where exactly to put this property. Can anyone tell me based on the following mapping file where I need to put inverse="true"?
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
auto-import="true"
namespace="LROLib.Domain"
assembly="LROLib">
<class name="TestResult" table ="Test_Results" >
<id name="Test_Result_Id" >
<generator class="native" />
</id>
<many-to-one name="Test_Result" class="Result" column="Result_Id" />
<many-to-one name="Test_Applicant" class="Applicant" column="Applicant_Id"/>
<property name="Test_Name" />
<property name="Value" />
<property name="Hi_Lo_Ind" />
<property name="Range" />
<property name="Unit_Of_Measure" />
<property name="Lo_Range" />
<property name="Hi_Range" />
<property name="Create_DateTime" update="false"/>
<property name="Update_DateTime" />
<property name="User_Name" />
</class>
</hibernate-mapping>
In most cases 'inverse' is to identify the relationship owner. For your particular case this should be in your Result
and Applicant
mappings.
You can read more in this blog post. To quote / paraphrase a particularly relevant statement from that article:
However the “inverse” keyword itself is not verbose enough, I would suggest change the [
inverse
] keyword to "relationship_owner
".In short,
inverse="true"
means this is the relationship owner, andinverse="false"
(default) means it’s not.