I'm looking at upgrading a legacy application from NHibernate 4 to NHibernate 5 and one of the changes is that now columns cannot be mapped multiple times. However I have an existing mapping which does exactly that and I'm not sure how to resolve it; I need to map the same column for two separate many-to-one relationships from the same entity.
Here is the existing mapping (which obviously works fine with NH 4):
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="..." namespace="...">
<class name="..." table="...">
<id name="Id">
<generator class="identity" />
</id>
<!-- various other properties -->
<many-to-one name="Board" column="Board_Code" />
<many-to-one name="Option">
<column name="Option_Code" />
<column name="Board_Code" />
</many-to-one>
</class>
</hibernate-mapping>
The problem here being the reuse of the Board_Code
column.
The column 'Board_Code' has already been added in this SQL builder
It seems to be possible to work around this as detailed in this answer and in this question when both a property and a many-to-one relationship need to be defined. The approach seems to be to just add insert="false" update="false"
to the property. However given I'm dealing with two relationships rather than a relationship and a property, I'm not clear on if there's any similar solution (and if so, what the implications would be).
Appreciate any help/advice.