I'm having problems with NHibernate mapping and I'm not sure if I made a noob mistake or whether I've run into a limitation of NHibernate
I have three domain objects with associated mapping hbm.xml files
Person
SpecialPerson
PersonCategory
public class Person
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="Person"
table="Person">
<id name="Id" column="PersonID">
<generator class="native" />
</id>
<property name="Name" />
</class>
</hibernate-mapping>
SpecialPerson derives from Person
public class SpecialPerson : Person
{
public virtual string MagicString { get; set; }
public virtual PersonCategory PersonCategory { get; set; }
}
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<joined-subclass name="SpecialPerson"
extends="Person">
<key column="PersonID" />
<property name="MagicString" />
<many-to-one name="PersonCategory" column="PersonCategoryID" cascade="save-update" />
</joined-subclass>
</hibernate-mapping>
and PersonCategory holds a collection of SpecialPersons <== this is what's causing me grief
public class PersonCategory
{
public virtual int Id { get; set; }
public virtual ICollection<SpecialPerson> Persons { get; set; }
}
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="PersonCategory"
table="PersonCategory">
<id name="Id" column="PersonCategoryID">
<generator class="native" />
</id>
<set name="Persons" table="SpecialPerson" inverse="true">
<key column="PersonCategoryID" />
<one-to-many class="SpecialPerson"/>
</set>
</class>
</hibernate-mapping>
When I attempt to create a session, I get an NHibernate.MappingException saying "Association references unmapped class: SpecialPerson"
Either I'm not using the proper syntax, as in I'm not supposed to specify the table attribute but something else when I'm trying to reference a derived type OR
NHibernate doesn't allow an object to hold a collection of a derived type unless that derived type is mapped in a table per concrete class inheritance mapping strategy. Can anyone enlighten me?