Hi,
I've got a situation where we have a base class with multiple subclasses, however some of the subclasses don't have any additional properties to the base class while others do. As a result, I want to provide an extra table only for the subclasses that need to express extra property values.
So, my base class mapping:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">
<class name="InputProfile" table="InputProfiles">
<id name="id" column="InputProfileID" unsaved-value="0" access="field">
<generator class="native" />
</id>
<discriminator column="InputInterface" type="System.Byte"/>
<version name="version" column="Version" access="field"/>
<property name="created" column="Created" update="false" access="field"/>
<property name="deleted" column="Deleted" access="field"/>
<property name="inputInterface" column="InputInterface" access="field" />
<property name="modified" column="Modified" update="false" access="field"/>
<many-to-one name="parentUser" column="ParentUserID" class="User" access="field" cascade="all"/>
</class>
</hibernate-mapping>
A subclass without additional properties (although they may come later):
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">
<subclass name="SmtpInputProfile" extends="InputProfile" discriminator-value="1">
</subclass>
</hibernate-mapping>
And a subclass with additional properties in it's own table:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Framework.Core.Entities" assembly="Framework.Core">
<joined-subclass name="FtpInputProfile" extends="InputProfile" table="FtpInputProfiles">
<key column="FtpInputProfileID" />
<property name="welcomeMessage" column="WelcomeMessage" access="field" />
</joined-subclass>
</hibernate-mapping>
Obviously these are only examples and the classes that use the table per joined subclass actually have many more additional properties.
When I try to do this I'm getting a mapping exception:
Code:
[MappingException: Could not format discriminator value 'Framework.Core.Entities.InputProfile' to sql string using the IType NHibernate.Type.ByteType]
NHibernate.Persister.EntityPersister..ctor(PersistentClass model, ISessionFactoryImplementor factory) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Persister\EntityPersister.cs:147
NHibernate.Persister.PersisterFactory.Create(PersistentClass model, ISessionFactoryImplementor factory) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Persister\PersisterFactory.cs:43
NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, Settings settings) in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Impl\SessionFactoryImpl.cs:139
NHibernate.Cfg.Configuration.BuildSessionFactory() in C:\Documents and Settings\Symon\My Documents\Visual Studio Projects\Third Party Components\nhibernate-0.9.0.0\src\NHibernate\Cfg\Configuration.cs:894
Is this a bug, or is what I'm trying to accomplish not possible?
Cheers,
Symon.