Hi
I've just recently started working with NHibernate , and have encountered a few problems. Is it possible that NHibernate might save two objects with same timestamps ?
In my case , I have a .Net 2.0 windows application which has a class called 'Message' which has two properties :
ModifiedDT CreateDT . They are mapped to NHibernate Type : TimeStamp.
NHibernate successfully saves the objects to the databases , but on some occassions ( whch are quite random) , I have found two records being inserted in my Message table with exactly same ModifiedDT and CreateDT values. .. as in same value right down to the millisecond.
The same timestamp records cause a lot of problem as they are later picked and processed by another application in ascending order of their ModifiedDT. The order in which the records get processed is very critical ....and with same timestamps records the order in which they get processed is not certain.
Here are the details :
NHibernate Version : 1.0.2.0
Mapping File :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Shared.Core.Messaging.Message" table="Message">
<id name="Id" column="MessageId" access="nosetter.camelcase">
<generator class="assigned"/></id>
<property name="Body" column="Message" type="Shared.Core.NHibernate.Messaging.UserTypes.MessageType, Shared.Core" not-null="true" update="false" access="nosetter.camelcase" />
<property name="Status" column="Status" type="Shared.Core.NHibernate.Messaging.UserTypes.MessageStatusType, Shared.Core" not-null="true" access="nosetter.camelcase" />
<property name="ModifiedDT" column="ModifiedDT" type="Timestamp" not-null="true" update="false" access="field.camelcase" />
<property name="CreateDT" column="CreateDT" type="Timestamp" not-null="true" update="false" access="field.camelcase" />
<component name="Header" class="Shared.Core.Messaging.MessageHeader, Shared.Core" access="nosetter.camelcase">
<property name="To" column="AddressTo" type="String" length="100" not-null="false" access="nosetter.camelcase" />
<property name="From" column="AddressFrom" type="String" length="100" not-null="false" access="nosetter.camelcase" />
<property name="Subject" column="Subject" type="String" length="50" not-null="false" access="nosetter.camelcase" />
</component>
/class>
</hibernate-mapping>
The folowing method is responsible for saving the object:
Code:
private void DoSave( Message message, ISessionContext session)
{
session.SaveOrUpdate(message);
}
whch calls:
public void SaveOrUpdate(object obj)
{
innerSession.SaveOrUpdate(obj);
}
innerSession is declared as :
private readonly ISession innerSession;
Database : SQL Server 2005
Any help is welcome !
Please let me know if any other details are required
Thanks