Hibernate version: 1.2.1.4000
Hi,
I have an intercepter that timestamps the objects in my database. It works fine for update and create, but with deletes the update of the timestamp generates an update when the session is completed.
If i remove the line ending with // HERE below, OnFlushDirty is not called when the session completes.
Nhibernate must think of the update of the timestamp as an update to the object. I am using this.session.FlushMode = FlushMode.Never, so why does nhibernate try to persist the object, when i havent called .saveorupdate/save/update on the object?
(the reason for updating the deleted object is, as it can be seen that it used for telling the clients when the delete occoured)
I thought that maybe evicting the object after deleting it would make nhibernate not want to try and persist the object on flush, but this causes an exception:
NHibernate.AssertionFailure: possible nonthreadsafe access to session
at NHibernate.Impl.SessionImpl.PostDelete(Object obj)
at NHibernate.Impl.ScheduledDeletion.Execute()
at NHibernate.Impl.SessionImpl.Execute(IExecutable executable)
at NHibernate.Impl.SessionImpl.ExecuteAll(IList list)
at NHibernate.Impl.SessionImpl.Execute()
at NHibernate.Impl.SessionImpl.Flush()
at ....Repository.OperationSession.Complete
the interceptor code:
public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, IType[] types)
{
UpdateTimestamp(entity, propertyNames, state); // HERE
eventDispatcher.AddChangeHint(new ChangeHint(ChangeType.Delete, (IDomainObject) entity));
}
private static void UpdateTimestamp(object entity, string[] propertyNames, object[] state)
{
DomainObject domainObject = entity as DomainObject;
if (domainObject != null)
{
int index = Array.IndexOf(propertyNames, "Timestamp");
if (index >= 0)
{
state[index] = DateTime.UtcNow;
}
}
}
|