nHibernate Table per Concrete Wrong Class Exception

firewall

New Member
I am having some problems with creating the xml mapping file for the following class hierarchy using Table per concrete way in nHibernate. I keep on getting "Wrong Class Exception" error. Can anyone help pointing me in the right direction?This is the definition of my abstract/parent class:\[code\]public abstract partial class AlertSpecification{ private long _alertSpecificationId; private string _specificationName; private bool _active; private int _createdBy; private DateTime _createdOn; public virtual long AlertSpecificationId { get { return _alertSpecificationId; } set { _alertSpecificationId = value; } } public virtual string SpecificationName { get { return _specificationName; } set { _specificationName = value; } } public virtual bool Active { get { return _active; } set { _active = value; } } public virtual int CreatedBy { get { return _createdBy; } set { _createdBy = value; } } public virtual DateTime CreatedOn { get { return _createdOn; } set { _createdOn = value; } }}\[/code\]This is the definition of my 1st child class:\[code\]public partial class ComponentSpecification : AlertSpecification{ private string _vehicleType; public virtual string VehicleType { get { return _vehicleType; } set { _vehicleType = value; } } }\[/code\]This is the definition of my 2nd child class:\[code\]public partial class ColdVehicleSpecification : AlertSpecification{ private double _sigmaThreshold; public virtual double SigmaThreshold { get { return _sigmaThreshold; } set { _sigmaThreshold = value; } } }\[/code\]This is the definition of my mapping file:\[code\]<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="IS.QueryPerformanceTest.Model" assembly="IS.QueryPerformanceTest.Model" > <class name="AlertSpecification" abstract="true"> <cache usage="read-write"/> <id name="AlertSpecificationId" type="Int64"> <generator class="hilo"/> </id> <property name="SpecificationName" column="Name" /> <property name="Active" /> <property name="CreatedBy" /> <property name="CreatedOn" /> <union-subclass name="ColdVehicleSpecification" table="AlertSpecificationColdVehicle"> <property name="SigmaThreshold" column="CVSigmaThreshold" /> </union-subclass> <union-subclass name="ComponentSpecification" table="AlertSpecificationComponent"> <property name="VehicleType" column="VehicleType" /> </union-subclass> </class></hibernate-mapping>\[/code\]This is the error that I am getting:Object with id: 1 was not of the specified subclass: IS.QueryPerformanceTest.Model.ColdVehicleSpecification (loading object was of wrong class [IS.QueryPerformanceTest.Model.ComponentSpecification])For some reasons, It always try to load ComponentSpecification even though I have specified in the code to load ColdVehicleSpecification.Does anyone have any clue what is wrong here?Please let me know if you need further information.Thanks in advance.
 
Back
Top