I’ve got a nested object (object with subobjects) that I’d like to retrieve from a repository associated with an active session from one database, evict it, and save it in another database (different session, different connection string, different repository). I have tried:
myISession.Evict(myObjectInstance);
My MappingConfiguration has
Conventions.Add(DefaultCascade.All())
for all types.
But I still get “NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions”. How can I remove the association with the original session?
OK, it turns out my object, in this case myObjectInstance was composed of objects from two different sessions, let’s call them A and B. myObjectInstance had properties myProp1 from session A, and myProp2 from session B. I was then to store the whole myObjectInstance in session B.
Unfortunately I was trying to evict myObjectInstance from session A, rather than just myProp1.
The solution was to: