Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

CompositeUserTypes CANNOT Short-circuit NullSafeSet #37

Description

@jbtule

Because this implementation is cited as an example across the internet. I feel it's important to point out a data corrupting bug in this generic implementation.

NullSafeSet needs to get called on each composite property with null when value is null.

If you don't and you have a batch save of objects with said composite type, any null value property will get be updated in the DB with the last nonnull value saved

public void NullSafeSet(IDbCommand cmd, object value, int index, ISessionImplementor session)
{
if (value == null)
return;
var propIndex = index;
for (var i = 0; i < _properties.Count; i++)
{
var property = _properties[i];
var propValue = property.GetValue(value, null);
NHibernateUtil.GuessType(property.PropertyType).NullSafeSet(cmd, propValue, propIndex, session);
propIndex++;
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions