I have a situation with Windows Forms where one window creates a session, queries some objects, then passes some of the objects to a 2nd window that manipulates the 1st window's objects properties. In particular, the 2nd window creates its own session to query objects (since it knows nothing of the 1st window's session), and assigns objects it queries to the properties of passed-in objects.
Back at the 1st window, if I try to flush the changes on the 1st session, if the 1st session had already queried the same entity (same ID) that was separately queried in the 2nd window and assigned to the 1st window's object, I get this exception:
Code:
NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [i]keyValue[/i], of class: [i]className[/i]
In the 2nd window, how could I possibly know that the passed-in object, to which I'm assigning a property with a newly-queried object, was queried in a different session, and that earlier session had also queried the same ID I just queried and assigned?
Do I have to pass sessions around too, and reuse the same session to avoid this? Or how could I tell the 1st session that the object I assigned that came from another session should replace any object with the same ID in its cache?[/i]