Code:
BaseClass.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="property">
<class name="Core.Services.BaseClass, Core.Services" table="Base_Object">
<id name="ProviderUserKey" column="Object_Id" access="nosetter.camelcase" unsaved-value="0">
<generator class="sequence">
<param name="sequence">object_id_seq</param>
</generator>
</id>
<discriminator column="Object_Type_ID" />
<property name="Name" column="Object_Name" not-null="true" />
<property name="Description" column="Description" length="255"/>
</class>
</hibernate-mapping>
SmallClass.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="property">
<subclass name="Core.Services.SmallClass, Core.Services"
extends="Core.Services.BaseClass, Core.Services"
discriminator-value="4">
</subclass>
</hibernate-mapping>
ExtentedClass.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-access="property">
<joined-subclass name="Core.Services.ExtendedClass, Core.Services" extends="Core.Services.BaseClass, Core.Services" table="Extended_Class" dynamic-update="true">
<key column="Object_ID"/>
<property name="LastActivityOn" column="Last_Activity" access="nosetter.camelcase" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate"/>
<property name="PendingRegistration" column="Pending_Registration"/>
</joined-subclass>
</hibernate-mapping>
And now the classes hierarchy:
Code:
using System;
namespace Core.Services {
public class BaseClass {
public string Description {
get {
return description;
}
set {
description = value;
}
}
private string description;
public string Name {
get {
return name;
}
set {
name = value;
}
}
private string name;
public int ProviderUserKey {
get {
return providerUserKey;
}
}
private int providerUserKey;
}
public class SmallClass: BaseClass {
}
public class ExtendedClass: BaseClass {
public DateTime LastActivityOn {
get {
return lastActivityOn;
}
set {
if (lastActivityOn != value) {
lastActivityOn = value;
}
}
}
private DateTime lastActivityOn;
public bool PendingRegistration {
get {
return pendingRegistration;
}
set {
if (pendingRegistration != value) {
pendingRegistration = value;
}
}
}
private bool pendingRegistration;
}
}
The class ExtendedClass will always have many more fields than SmallClass and I want it to be persisted in table Extended_Class.
The problem is that NHibernate never populates discriminator column Object_Type_ID when this combination of <joined-subclass> and <subclass> is used.
I hope I managed to express cleary the issue I'm having.
Regards,
Robert