Given the tables:
TableA
aId
...
TableB
bId
...
TableC
aId
cId // Maps to TableB.bId
In other words TableA and TableB are only related through an entry in TableC.
I want the following classes:
public class ClassA
{
aId
...
}
public class ClassB
{
bId
...
}
public class ClassD : ClassA
{
ClassB
}
So that ClassD has all of the properties of ClassA with the addition of a single instance of ClassB.
My initial thought was to use:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping auto-import="false" xmlns="urn:nhibernate-mapping-2.2">
<class name="ClassD" lazy="false" table="TableA" polymorphism="explicit">
<id name="aId" column="aId" type="Guid">
<generator class="CustomGuidGenerator" />
</id>
...
<many-to-one name="ClassB" column="cId" class="ClassB" cascade="all" not-found="ignore" />
</class>
</hibernate-mapping>
Obviously, in this mapping, there is no cId in TableA nor is there a way in many-to-one to specify a table. So, how do you map a single entity via an intermediate join table?
Not sure what is exactly in your tables (is TableC.aId a reference to TableA.aId ?), but maybe you can go for a table-per-subclass strategy ( see for example http://docs.huihoo.com/hibernate/nhibernate-reference-1.2.0/inheritance.html )
About
ClassB, it should have it’s own mapping file, and the system will be able to compute the table name (TableB) for the many-to-oneClassBproperty.