Illegal attempt to associate a collection with two open sessions

88 views
Skip to first unread message

Giulio Petrucci

unread,
Jul 19, 2010, 4:35:51 AM7/19/10
to nhu...@googlegroups.com
Hi there,

I've been lurking this mailing list for a while and this is my first post. :-)
My model is a matrix, like this:

class Matrix {
IEnumerable <Column> ColumnSet { get; }
IEnumerable <Row> RowSet { get; }
void AddColumn(Column c);
void AddRow(Row r);
}

class Column
{
Matrix Matrix { ... }
}

class Row
{
Matrix Matrix { ... }
IEnumerable<Element> ElementSet { get; }
}

class Element {
Int32 Value { get; }
Row Row { get; }
Column Column { get; }
}

Every class has an Id property, whici is of Guid type.
When I add a Column (AddColumn() method), automatically a new Element
is added for each Row in the RowSet.
When I add a Row (AddRow() method), automatically an element for each
Column in the ColumnSet si added to the Row I'm adding.
In the mapping files, for Matrix/Column/Row/Element I've set:
cascade="all-delete-orphan". I need to handle one session only to
read data in their actual persistent state (in a sort of db polling):

Guid id = ...;
ISessionFactory sf = ...;
using (ISession sf.OpenSession())
{
Element e = s.Get<Element>(id);
//something here;
}

..and another session to rea/write data:

int newValue = ...;
ISession s = ...;
Element r = ...;

using (ITransaction tx = s.BeginTransaction())
{
e.Value = newValue;
s.SaveOrUpdate(e);
tx.Commit();
}

and here I get an "Illegal attempt to associate a collection with two
open sessions".
As I'm quite a newbie, my my questions are:
1. What does it mean? ;-)
2. How can I fix it?

Thanks in advance. Have a nice day/week,
Giulio

--

Fabio Maulo

unread,
Jul 19, 2010, 7:47:43 AM7/19/10
to nhu...@googlegroups.com
That mean that is you do first ISession... and then Element ... and then ISession ... there is a possibility that the collection... will be associated with ... sessions.


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Vekaz Turković

unread,
Jul 19, 2010, 2:17:59 PM7/19/10
to nhu...@googlegroups.com
It means what it says :p

You cannot associate an entity with two sessions at the same time. I just took a glance at your code, but if you do need those two sessions, you have to first detach entity from first session if you want to attach it to second one. If you do that, you'll solve your immediate problem, but... I recommend reading about sessions and session management before moving any further.

HTH, peace :)

Reply all
Reply to author
Forward
0 new messages