Skip to content

NH-3898 - Configuring a property with generated="insert" turns "Property.IsUpdatable" into"false" even using update="true" in the xml mapping file. #1371

@nhibernate-bot

Description

@nhibernate-bot

hailtondecastro created an issue — 11th August 2016, 23:16:19:

Configuring a property with generated="insert" turns "Property.IsUpdatable" into"false" even using update="true" in the xml mapping file.


hailtondecastro added a comment — 11th August 2016, 23:25:55:

Please consider keep this issue as Critical, as it does not break the application, but it makes the applications migrated from NHibernate version 2 to 3 or 4 generates inconsistent data within the database.
As soon as I can, I will send a pull request.


hailtondecastro added a comment — 11th August 2016, 23:35:35:

There is a workaround for the problem:

...
{
...
    config.AfterBindMapping <ins>= new EventHandler<NHibernate.Cfg.BindMappingEventArgs>(config_AfterBindMapping);
...
}
...
void config_AfterBindMapping(object sender, NHibernate.Cfg.BindMappingEventArgs e)
{
    NHibernate.Cfg.Configuration config = sender as NHibernate.Cfg.Configuration;
    if (config != null)
    {
        foreach (object mappingItem in e.Mapping.Items)
        {
            NHibernate.Cfg.MappingSchema.HbmClass hbmClass = mappingItem as NHibernate.Cfg.MappingSchema.HbmClass;
            if (hbmClass != null)
            {
                NHibernate.Mapping.PersistentClass persistentClass = null;
                if (hbmClass.EntityName != null)
                {
                    persistentClass = config.GetClassMapping(hbmClass.EntityName);
                }
                else
                {
                    Type type = Type.GetType(e.Mapping.@namespace </ins> "." <ins> hbmClass.name </ins> ", " + e.Mapping.assembly, true);
                    persistentClass = config.GetClassMapping(type);
                }

                Dictionary<String, NHibernate.Cfg.MappingSchema.HbmProperty> propertyMappingDic =
                    new Dictionary<string, NHibernate.Cfg.MappingSchema.HbmProperty>();

                foreach (object propertyObject in hbmClass.Properties)
                {
                    NHibernate.Cfg.MappingSchema.HbmProperty propertyMapping = propertyObject as NHibernate.Cfg.MappingSchema.HbmProperty;
                    if (propertyMapping != null)
                    {
                        propertyMappingDic<propertyMapping.Name> = propertyMapping;
                    }
                }

                foreach (NHibernate.Mapping.Property property in persistentClass.PropertyIterator)
                {
                    if (propertyMappingDic.ContainsKey(property.Name))
                    {
                        NHibernate.Cfg.MappingSchema.HbmProperty propertyMapping = propertyMappingDic<property.Name>;

                        property.IsUpdateable = propertyMapping.updateSpecified ? propertyMapping.update : true;
                    }
                }
            }
        }
    }
}

hailtondecastro added a comment — 12th August 2016, 1:32:53:

Test case and fix are on these Pull requests:
Test case and fix to NH-3898 Pull Request #499
Test case and fix to NH-3898 Pull Request #500

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions