Problem: nHibernate can't find the entity class when it appears as a <subclass> of a <joined-subclass>
Exception: "Unknown entity class: Domain.Unit"
Description (you can skip this and go directly to the class map file and other info that appears after this): I have an inheritance hierarchy where an abstract class, AbstractUnit, implements an interface, IDeviceContainer. The IDeviceContainer interface (and those classes that implement it such as AbstractUnit) has a table-per-subclass inheritance implementation (tblDeviceContainer is for the interface, tblUnit is for all Units & it has a foreign key to tblDeviceContainer, and tblNode is for Nodes & it has a foreign key to tblDeviceContainer).
AbstractUnit is itself an inheritance hierarchy with concrete subclasses, Unit and UnitSection. This inheritance implementation is implemented with a table-per-class-hierarchy (tblUnit has both Unit and UnitSection). The AbstractUnit is a <joined-subclass> of the class mapping, IDeviceContainer. Unit and UnitSection are <subclass>es under AbstractUnit's <joined-subclass> element.
Domain Object Model:
I have a class hierarchy as follows:
+ EDomain (abstract base class)
+ + AbstractUnit (abstract base class), implements IDeviceContainer
+ + + Unit (concrete subclass of AbstractUnit)
+ + + UnitSection (concrete subclass of AbstractUnit)
C# classes/interfaces:
Domain/object model (all are in the namespace, Domain):
public interface IDeviceContainer { ... }
public abstract class EDomain { ... }
public class AbstractUnit : EDomain, IDeviceContainer { ... }
public class Unit : AbstractUnit { ... }
public class UnitSection : AbstractUnit { ... }
Code between sessionFactory.openSession() and session.close():
Unit unit = new Unit();
...
session.Save(unit);
Mapping documents:
<class name="Domain.IDeviceContainer, Domain" table="dbo.tblDeviceContainer">
<joined-subclass name="Domain.Node, Domain" table="tblNode">
<key column="FK_pDeviceContainerID"/>
</joined-subclass>
<joined-subclass name="Domain.AbstractUnit, Domain" table="tblUnit">
<key column="FK_pDeviceContainerID"/>
<subclass name="Domain.Unit, Domain" discriminator-value="Unit">
</subclass>
<subclass name="Domain.UnitSection, Domain" discriminator-value="UnitSection">
</subclass>
</joined-subclass>
</class>
</hibernate-mapping>
_________________ metazone
|