Hello all,
I have a base class (clsA) that has a number of subclasses (clsA1, clsA2...) . These objects relate many-to-one to another class (clsB).
I wish to have an ISet on clsB that contains all of the clsA instances. This collection needs to contain a hetergenous mix of the subclasses (clsA1, clsA2 etc).
I am having difficulty creating the map...
Quote:
Exception: NHibernate.WrongClassException
Message: Object with id: 71474 was not of the specified sublcass: OPWLibrary.CDT.iOPWCoreData (Discriminator: FCST )
Can someone please tell me, is it possible to get NH to achieve what I need?
I have included some extracts from my maps if they will help.
Thank you very much in advance,
Damien Sawyer
From clsB Map
Code:
<set name="_oPWCoreDataItemsNH" access="field" inverse="true" lazy="true">
<key column="cDataTypeID"/>
<one-to-many class="OPWLibrary.CDT.iOPWCoreData,OPWLibrary"/>
</set>
From clsB Code
Code:
private ISet _oPWCoreDataItemsNH = new HashedSet();
From clsA{1,2...} Map
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="OPWLibrary.CDT.iOPWCoreData, OPWLibrary" table="tblCoreData">
<id name="CoreDataID" column="iCoreDataID">
<generator class="assigned" />
</id>
<discriminator column="cDataTypeID"/>
<!--Out of interst, need to mark this as insert=false, update=false, because cDataTypeID is used above (as the discriminator)-->
<many-to-one name="CoreDataType" column="cDataTypeID" insert="false" update="false" not-null="true"/>
<subclass name="OPWLibrary.CDT.clsCDT_SOH, OPWLibrary"
discriminator-value="SOH" >
</subclass>
...
<subclass name="OPWLibrary.CDT.clsCDT_FCST, OPWLibrary"
discriminator-value="FCST" >
</subclass>
</class>
</hibernate-mapping>
From clsA Code
Code:
namespace OPWLibrary.CDT
{
/// <summary>
/// Summary description for iOPWCoreData.
/// </summary>
public interface iOPWCoreData
{
clsCoreDataType CoreDataType{get;set;}
...
}
}