Reputation: 9394
I working on a project that uses NHibernate. My problem is when I'm trying to add an object that contains a list of objects I receive the following exception:
Illegal attempt to associate a collection with two open sessions from Session.Save method
I don't know what is the problem or how to solve it, please if any one can help I will appreciated.
Upvotes: 2
Views: 3955
Reputation: 7803
You are having session management problems. It seems that you are using an object from one session as collection item in a collection from some other session. Using multiple parallell sessions is usually not a good practice (at least not from the same thread).
Read up on Unit of Work here; http://www.nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx .
There is an excellent and free implementation of this in Rhino.Commons, you can read more about that here: http://ayende.com/blog/archive/2007/06/08/rhino-commons-repositorylttgt-and-unit-of-work.aspx.
Upvotes: 5
Reputation: 1126
It seems that objects you try to add were loaded from different session that the destination object into which you are attaching them.
Upvotes: 0