-
Notifications
You must be signed in to change notification settings - Fork 684
Closed
Description
I am getting the following error from nhibernate:
XmlSchemaValidationException: The element 'union-subclass' in namespace
'urn:nhibernate-mapping-2.2' has invalid child element 'joined-subclass'
in namespace 'urn:nhibernate-mapping-2.2'.
My setup is as follows:
public abstract class AbstractBaseEntity
{
public virtual string Id { get; set; } = Guid.NewGuid().ToString();
public virtual AbstractIntermediateEntity Intermediate { get; set; }
public virtual ConcreteEntity Concrete { get; set; }
}
public abstract class AbstractIntermediateEntity : AbstractBaseEntity
{
public virtual string Property { get; set; }
}
public class ConcreteEntity : AbstractIntermediateEntity
{
public virtual string OtherProperty { get; set; }
}
public class Configuration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type) => base.ShouldMap(type) && typeof(AbstractBaseEntity).IsAssignableFrom(type);
}
...
var sessionFactory = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.UsingFile(dataStorage.DataStorage.PathToDbFile))
.Mappings(m => m.AutoMappings
.Add(AutoMap.AssemblyOf<AbstractBaseEntity>(new Configuration())
.Override<AbstractBaseEntity>(_ => _.UseUnionSubclassForInheritanceMapping())
.IncludeBase<AbstractBaseEntity>()
.IncludeBase<AbstractIntermediateEntity>()))
.BuildSessionFactory();
The hmb I am getting looks like this, which is wrong:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" name="ApplicationFramework.Models.AbstractBaseEntity, ApplicationFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" table="`AbstractBaseEntity`" abstract="true">
<id name="Id" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<many-to-one class="ApplicationFramework.Models.AbstractIntermediateEntity, ApplicationFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" name="Intermediate">
<column name="Intermediate_id" />
</many-to-one>
<many-to-one class="ApplicationFramework.Models.ConcreteEntity, ApplicationFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" name="Concrete">
<column name="Concrete_id" />
</many-to-one>
<union-subclass name="ApplicationFramework.Models.AbstractIntermediateEntity, ApplicationFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" abstract="true">
<property name="Property" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Property" />
</property>
<joined-subclass name="ApplicationFramework.Models.ConcreteEntity, ApplicationFramework, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" abstract="true">
<key>
<column name="AbstractIntermediateEntity_id" />
</key>
<property name="OtherProperty" type="System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="OtherProperty" />
</property>
</joined-subclass>
</union-subclass>
</class>
</hibernate-mapping>
Note that I can get this to work with fluent mappings, using ClassMap, SubclassMap and SubclassMap but I really ought to be using Automap!