Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoMap with union-subclass does not work with a sub-subclass #410

Closed
fabsulous opened this issue Apr 18, 2018 · 1 comment
Closed

AutoMap with union-subclass does not work with a sub-subclass #410

fabsulous opened this issue Apr 18, 2018 · 1 comment
Labels
Milestone

Comments

@fabsulous
Copy link

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!

@hazzik
Copy link
Member

hazzik commented Sep 18, 2020

Fixed by #334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants