Saturday 12 December 2015

NonUniqueObjectException was caught - a different object with the same identifier value was already associated with the session: 345, of entity: Kasani.RackApp.Model.Data.Domain.Employee

NonUniqueObjectException was caught            (NHibernate Exception)

a different object with the same identifier value was already associated with the session: 345, of entity: Kasani.RackApp.Model.Data.Domain.Employee


The Exception Came Because The Two Different Objects Having Same Id, Which The NHibernate Reads The Id To SaveOrUpdate The Data Accordingly Based On Id.

So To Resolve That, I Had Used

Session.Clear() and
Session.Flush() Before SaveOrUpdate() method...i.e.,

Session.Clear();
Session.Flush();
object1=SaveOrUpdate(object1);

foreach(var item in object2)
{
   otherObjectRepository.SaveOrUpdate(item);
}


Now It Works Fine.


No comments:

Post a Comment

Note: only a member of this blog may post a comment.