When I use session.update(object) I get below error and how can I rectify this error? I have even tried Session.evict(object) still it is not solved for the below error
a different object with the same identifier value was already associated with the session: 10, of entity: Sales.Entities.TTable
Is your application a web application?
Use Session.Merge(object)
In web applications you sometimes serialize and de-serialize objects, then you do so you create new objects, so even if the NHibernate objects has the same ID, the object reference is different. Then you try to update your de-serialized object, NHibernate detects another object with the same ID but different reference pointer thus don't know which object in your memory is the "correct" one.
the Merge() method is used in these cases, so you can update objects that in your web application.
What are you trying to accomplish, the error means that you are trying to update an object that hibernate already has its internal cache but you are sending a different object reference.
Using Session.Merge is a possibility but in most cases if you are in a web context you should already have the reference somewhere because you most likely use Session per request. So the question is:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With