Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:1.0.3.0
the data base contains a constraint of uniqueness on the object's name
Code:
protected virtual void Save(object obj)
{
ISession _session = null;
DateTime _version = ((AbstractBaseEntity)obj).VersionTimeStamp;
try
{
if(SessionScope.Current == null) _session = HibernateRegMgr.SessionFactory.OpenSession();
else _session = SessionScope.Current;
_session.SaveOrUpdate(obj);
_session.Flush();
}
catch (HibernateException e)
{
//((AbstractBaseEntity)obj).VersionTimeStamp = _version;
LogControler.LogError(ErrorMsg.SaveDAOError + obj.ToString(), e);
HibernateExceptionAdaptator.ThrowCustomAppException(e);
}
catch (Exception e)
{
LogControler.LogError(ErrorMsg.SaveDAOUnexpectedError + obj.ToString(), e);
throw new nSherpaDALGenericException(e);
}
finally
{
if(SessionScope.Current==null)CloseSession(_session);
}
}
when I save an object with a name whose exist in the database, an exception is thrown, it raise of the database.
The Problem is that the version (TimeStamp) of the object is incremented but it was not saved. that generate another problem when I want to sagve this object afterward, another exception is thrown because NHibernate want to do "Update" on the object but it does not exist in the database
The Second error message:
Quote:
2006-12-21 18:08:24,300 [2732] ERROR NHibernate.StaleObjectStateException [(null)] - An operation failed due to stale data
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction for nSHERPA.Core.NHibernateImpl.DML.Production.ProductionRequestStatus instance with identifier: dd05009a-0f10-4499-8df7-71c1b7dc2619
2006-12-21 18:08:24,300 [2732] ERROR NHibernate.Impl.SessionImpl [(null)] - could not synchronize database state with session
NHibernate.StaleObjectStateException: Row was updated or deleted by another transaction for nSHERPA.Core.NHibernateImpl.DML.Production.ProductionRequestStatus instance with identifier: dd05009a-0f10-4499-8df7-71c1b7dc2619