Skip to content
This repository

mapping.Component throws exception in IAutoMappingOverride`1 #104

Closed
hazzik opened this Issue October 17, 2011 · 1 comment

1 participant

Alexander I. Zaytsev
Alexander I. Zaytsev

I've following configuration:

public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
    private readonly HashSet<Type> components = new HashSet<Type>
                                                    {
                                                        typeof (DocumentNumber)
                                                    };


    public override bool IsComponent(Type type)
    {
        return components.Contains(type);
    }

    public override string GetComponentColumnPrefix(FluentNHibernate.Member member)
    {
        //replaces camel case with underscores "IncomingDocument" => "INCOMING_DOCUMENT"
        //and adds undersocre at end
        return string.Format("{0}_", Regex.Replace(member.Name, "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1_").ToUpper());
    }

    //rest of configuration
}

And alteration for my entity.

public class IncomingDocumentMap : IAutoMappingOverride<IncomingDocument>
{
    public void Override(AutoMapping<IncomingDocument> mapping)
    {
        mapping.Component(x => x.IncomingNumber) //incoming number is type of DocumentNumber
            .ColumnPrefix("INCOMING_"); // I need to override default column prefix for component. 
    }
}

When I try to build sesion factory I've got following exeption:

System.InvalidOperationException: Tried to add component 'IncomingNumber' when already added.
at FluentNHibernate.MappingModel.MappedMembers.AddComponent(IComponentMapping componentMapping) in d:\Builds\FluentNH\src\FluentNHibernate\MappingModel\MappedMembers.cs: line 133
at FluentNHibernate.Automapping.Steps.ComponentStep.Map(ClassMappingBase classMap, Member member) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\Steps\ComponentStep.cs: line 26
at FluentNHibernate.Automapping.AutoMapper.TryMapProperty(ClassMappingBase mapping, Member member, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 170
at FluentNHibernate.Automapping.AutoMapper.<>c__DisplayClasse.<ProcessClass>b__d(Member x) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 158
at FluentNHibernate.Utils.CollectionExtensions.Each(IEnumerable`1 enumerable, Action`1 each) in d:\Builds\FluentNH\src\FluentNHibernate\Utils\CollectionExtensions.cs: line 15
at FluentNHibernate.Automapping.AutoMapper.ProcessClass(ClassMappingBase mapping, Type entityType, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 156
at FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedMembers) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 43
at FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoMapper.cs: line 186
at FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 209
at FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings() in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 173
at FluentNHibernate.Automapping.AutoPersistenceModel.Configure(Configuration configuration) in d:\Builds\FluentNH\src\FluentNHibernate\Automapping\AutoPersistenceModel.cs: line 199
at FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg, PersistenceModel model) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\AutoMappingsContainer.cs: line 86
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs: line 80
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 249 


FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs: line 264

If I remove typeof(DocumentNumber) from component types I've got exception which says that property is references unmapped class

NHibernate.MappingException: An association from the table INCOMING_DOCUMENT refers to an unmapped class: DocumentNumber
at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
at NHibernate.Cfg.Configuration.SecondPassCompileForeignKeys(Table table, ISet done)
at NHibernate.Cfg.Configuration.SecondPassCompile()
at NHibernate.Cfg.Configuration.BuildSessionFactory()

If I write component with inlined configuration that all works fine:

public class IncomingDocumentMap : IAutoMappingOverride<IncomingDocument>
{
    public void Override(AutoMapping<IncomingDocument> mapping)
    {
        mapping.Component(x => x.IncomingNumber,
                            c =>
                            {
                                c.Map(x => x.Number).Column("INCOMING_NUMBER");
                                c.Map(x => x.Date).Column("INCOMING_DATE");
                            });
     }
}
Alexander I. Zaytsev hazzik referenced this issue from a commit in hazzik/fluent-nhibernate October 18, 2011
Alexander I. Zaytsev Fix for issue #104: FNH should mark ReferenceComponent as mapped when…
… it is overridden in IAutoMappingOverride
643634d
Alexander I. Zaytsev hazzik referenced this issue from a commit in hazzik/fluent-nhibernate April 27, 2012
Alexander I. Zaytsev Fix for issue #104: FNH should mark ReferenceComponent as mapped when…
… it is overridden in IAutoMappingOverride
79c51b7
Alexander I. Zaytsev
hazzik commented July 02, 2012

Please merge it.

Alexander I. Zaytsev hazzik closed this August 13, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.