dzenesiz
dzenesiz

Reputation: 1552

Property mapping has wrong number of columns error after upgrading to NHibernate 5.5.2

I upgraded NHibernate from 4.0.4.4000 and 4.0.0.4000 (both versions were used depending on the project) to 5.5.2.

I am receiving the following error:

property mapping has wrong number of columns: Solution.Project.MainEntity.MyComponent type: component[SomeFieldsCollection,ComponentInfo]

when calling BuildSessionFactory() on Nhibernate.Cfg.Configuration instance.

In version 4 of the library, I never got this error.

This is the mapping:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="iPublisher.Domain.DTOs.EntryTool" assembly="iPublisher.Domain">

    <class name="MainEntity" table="mainTable"  discriminator-value="true">
        <composite-id name="ID" class="MyCompositeId">
            <key-property name="ID"/>
            <key-property name="ID_Other"/>
        </composite-id>
        <component name="MyComponent" class="MyComponent">
            <set name="SomeFieldsCollection" inverse="true" cascade="all-delete-orphan">
                <key>
                    <column name="MyID"/>
                    <column name="MyID_Other"/>
                </key>
                <one-to-many class="SomeField" />
            </set>
            <one-to-one name="ComponentInfo" fetch="select" lazy="false" class="MyComponentInfo" cascade="all-delete-orphan"/>
        </component>
    </class>

</hibernate-mapping>

And here are the relevant classes (names not real, of course):

public class MainEntity : EntityBase<MyCompositeId>
{    
    public virtual MyComponent MyComponent { get; set; } = new MyComponent();
}

public class MyComponent
{
    public virtual ISet<SomeField> SomeFieldsCollection { get; set; }
    public virtual MyComponentInfo ComponentInfo { get; set; }
}

public class SomeField : FieldBase { }

public class FieldBase : EntityBase<int>
{
    [ScriptIgnore]
    public virtual MainEntity MyMainEntity { get; set; }
    public virtual int Value1 { get; set; }
    public virtual int Value2 { get; set; }
    public virtual string Value3 { get; set; }
    public virtual bool Value4 { get; set; }
    public virtual ISet<SomeType> SomeCollection { get; set; }

    public override object Clone()
    {
        var clone = (FieldBase)MemberwiseClone();
        return clone;
    }
}

public class MyCompositeId : IIdentifier, ICloneable
{
    private int _ID;
    private int _ID_Other;

    public MyCompositeId() { }

    public MyCompositeId(int ID, int ID_Other)
    {
        _ID = ID;
        _ID_Other = ID_Other;
    }

    public virtual int ID
    {
        get { return _ID; }
        set { _ID = value; }
    }

    public virtual int ID_Other
    {
        get { return _ID_Other; }
        set { _ID_Other = value; }
    }
}

I looked online, but I mostly find examples for FluentNHibernate. In the end, I looked through the source code, but I cannot make sense of it. I can only assume which concrete type in the source abstraction (AbstractType) my instance resolves to, but it definitely seems that the issue is linked to some column span which is used to determine the validity of the property mapping (by calling the IsValid() method)...

Any form of help is greatly appreciated.

Upvotes: 0

Views: 75

Answers (0)

Related Questions