views:

33

answers:

0

So I have scavenged the internet for a while now and am still stumped on this current issue I am facing with nHibernate: I have two tables that I have mapping files for. Table A stores information about "Things", and Table B stores how these "Things" are related.

The problem is as follows. Table A is mapped to the Thing class. Table B needs several many-to-one mappings on ThingNames and ThingIDs to table A in order to retrieve actual Thing objects. None of these mappings fall on primary keys by design. The real problem is that Table A can have many duplicates of ThingName, but only one ThingID, so I need to map both the ThingNames AND ThingIDs in Table B to the correct columns/properties in Table A.

After many many revisions, here are the current mapping portions that are giving me trouble.

Table A mapping:

...
<properties name="ThingIDThingName">
  <property name="ThingId" type="long" insert="false" update="false">
    <column name="THING_ID" />
  </property>
  <property name="ThingName" type="AnsiString" insert="false" update="false">
    <column name="THING_NAME" />
  </property>
</properties>
...

Table B mapping:

...
<many-to-one name="Thing1" class="Thing" property-ref="ThingIDThingName">
  <column name="THING_ID"/>
  <column name="THING1_NAME"/>
</many-to-one>

<many-to-one name="Thing2" class="Thing" property-ref="ThingIDThingName">
  <column name="THING_ID"/>
  <column name="THING2_NAME"/>
</many-to-one>

<many-to-one name="Thing3" class="Thing" property-ref="ThingIDThingName">
  <column name="THING_ID"/>
  <column name="THING3_NAME"/>
</many-to-one>
...

Errors returned when run.

NHibernate.MappingException: property [ThingIDThingName] not found on entity [Thing]
NHibernate.MappingException: property-ref [ThingIDThingName] not found on entity [Thing]

Things to note:

-The many-to-one works completely fine if I am only mapping to a single column and that columns respective property.

-I get the exact same errors when removing the Table A mapping code above.

-The documentation on using the tag has only been seen in Hibernate guides, and not nHibernate guides (perhaps it is not fully compatable with .NET?)

-very relevant resource on this issue https://forum.hibernate.org/viewtopic.php?f=1&amp;t=991369... this is where I have found the most similar issue, yet the proposed solution doesn't work.

Any and all help is greatly appreciated. Thanks in advance!