Using Sharp Architecture / Fluent NHibernate, I set-up a Version property (with an int) for my class, however, even though updating its objects correctly updates the Version number, no error is thrown and the versions are basically merged instead of throwing an exception.
public class MyClassMap : IAutoMappingOverride<MyClass>
{
public void Override(AutoMapping<MyClass> mapping)
{
mapping.Version(x => x.Version);
mapping.OptimisticLock.Version();
}
}
Notice the version is different between two concurrent commits, yet nothing happens.
What gives?
Edit: Here’s the code:
public ActionConfirmation SaveOrUpdate(IncidenciaDetalleModel model)
{
Incidencia incidencia = model.Codigo == null
? new Incidencia(Convert.ToInt32(model.Solicitante.Id))
: Load(model.Guid);
TransferFormValuesTo(incidencia, model);
// Invoke Sharp NHibernate's SaveOrUpdate()
Incidencia saved = base.SaveOrUpdate(incidencia);
return ActionConfirmation.CreateSuccessConfirmation(saved);
}
private void TransferFormValuesTo(Incidencia incidencia, IncidenciaDetalleModel model)
{
incidencia.Resumen = model.Resumen.Trim();
incidencia.Descripcion = model.Descripcion.Trim();
incidencia.Solicitante = model.Solicitante.Id.ToString(CultureInfo.InvariantCulture);
incidencia.Regional = regionalTask.Load(model.Regional.GetRegionalId());
}
you said the Version updates fine so not applying Conventions fall out.
i guess there is no real concurrent update. you use
Load(model.Guid)which doesnt load the object from database but creates a proxy for it. it is loaded inTransferFormValuesToupdated and immediatly saved. Only betweenTransferFormValuesToandSaveOrUpdate()there can be a race condition leading to stale objects.you could enable logging for “NHibernate.SQL” to see if the Update of client 1 really is after the the SELECT of client 2