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

FNH 1.3: Mapping to the ICompositeUserType broken #93

Open
sergey-legenkiy opened this issue Sep 16, 2011 · 6 comments
Open

FNH 1.3: Mapping to the ICompositeUserType broken #93

sergey-legenkiy opened this issue Sep 16, 2011 · 6 comments

Comments

@sergey-legenkiy
Copy link

Yesterday I grab last available sources of FNH to make it possible to use it with NH 3.2.0.4GA. But after update to new version (1.3) I start getting the following error:

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

  • Database was not configured through Database method.
    ---> NHibernate.MappingException: property mapping has wrong number of columns: CashDepartment.Server.DomainModel.Enities.Service.Rate type: component[RateType,PaymentCondition,FixedAmountData,FixedCostOfArivalData,PercentageData]
    at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\PersistentClass.cs:line 954
    at NHibernate.Mapping.RootClass.Validate(IMapping mapping) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Mapping\RootClass.cs:line 371
    at NHibernate.Cfg.Configuration.ValidateEntities() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1030
    at NHibernate.Cfg.Configuration.Validate() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 958
    at NHibernate.Cfg.Configuration.BuildSessionFactory() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Cfg\Configuration.cs:line 1250
    at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()
    --- End of inner exception stack trace ---
    at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory()

This happens then I map ICompositeUserType:
C# Map(m => m.Amount).CustomType<MoneyCompositeType>();

After call CustomType method, returned PropertyPart object contains correct number of columns, but then FNH visitor visit this property during NH mapping generation it Columns collection contains only one column named as Property.

May be this information will be useful: this property located in class that mapped as Component.

I think this is the bug. How can I fix it?

@sergey-legenkiy
Copy link
Author

Any news? I must migrate to the NH mapping from code?
Issue not closed... this is mistake!

@toddlangdon
Copy link

I am getting this same exception while trying to map an ICompositeUserType - is this an issue with FNH or not?

@EnemyArea
Copy link

its still buggy. Columns.Clear() doesn't help

Edit: Ok, first set the CustomType and than add the columns with an clear:
this.Map(x => x.MapSize).Not.Nullable().CustomType().Columns.Clear().Columns.Add("MapWidth", "MapHeight");

@chester89
Copy link
Collaborator

Can someone provide full code sample on that?

@chester89 chester89 reopened this Jun 4, 2014
@drusellers
Copy link

I'm getting it on a Component map with no user types. I'll have to see if I can isolate it down.

@drusellers
Copy link

Ok, When I use a component map like

            Component(x => x.Volume, c =>
            {
                c.Map(o => o.Measure);
                c.Map(o => o.UnitOfMeasure);
            });

Where Measure and UnitOfMeasure are user types

and I'm applying this Component convention.

    public class ComponentPropertyConvention :
        IPropertyConvention,
        IPropertyConventionAcceptance
    {
        public void Apply(IPropertyInstance instance)
        {
            var y = instance.EntityType.Name.ToPostgresName();
            var z = instance.Property.Name.ToPostgresName();
            var name = $"{y}_{z}";
            instance.Column(name);
        }

        public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
        {
            criteria.Expect(isThisPropertyAComponent);
        }

        bool isThisPropertyAComponent(IPropertyInspector prop)
        {
            var propertyType = prop.Property.PropertyType;
            var propertyName = prop.Name;
            var entityType = prop.EntityType;

            //an entity
            var isComponent = !entityType.Implements(typeof(Identifiable<>))
                //not an egg primitive
                && !entityType.Implements(typeof(ValueObject<>))
                //not a primitive
                && !entityType.IsPrimitive
                //not a value type (int, long, decimal, etc)
                && !entityType.IsValueType;

            //should be a class that is not identifiable
            return isComponent;
        }
    }

I get the issue.

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

No branches or pull requests

5 participants