berets wrote:
I needed to add a session.Refresh() on my entity to check if it was changed before update it, now the check works fine but when i try to update my entity i'm getting the following error :
a different object with the same identifier value was already associated with the session
before i make the refresh all was ok.
in another point of my app, i see that if i call a session.Clear() before call the Update() the error was not generated.
I think you may want to re-read the NHibernate documentation. I think it's clear that Update() doesn't do what you think it does.
Update() is intended to associate an existing object with a given session telling NHibernate this record will already exist and these values should be updated to the database. It does not mean "Call an UPDATE SQL call." NHibernate relies on the session's tracking which will tell it when a given object is dirty or not. When you call flush and there are dirty objects in the session NHibernate will save all of the changes to those objects.
Since you are calling Refresh() I know that object is already in the session. Secondly since you are calling Refresh() the object will not be dirty until another update is made to that object. If you call Refresh() change a property of that object, and then call Flush() the changes you made to that object will be persisted to the data store.
Hope that helps...