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

CompositeUserTypes CANNOT Short-circuit NullSafeSet #37

Open
jbtule opened this issue Feb 20, 2020 · 0 comments
Open

CompositeUserTypes CANNOT Short-circuit NullSafeSet #37

jbtule opened this issue Feb 20, 2020 · 0 comments

Comments

@jbtule
Copy link

jbtule commented Feb 20, 2020

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++;
}
}

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

No branches or pull requests

1 participant