Session, is not threadsafe. So the best (and only) practice is to not use a
session in multiples threads.
Why do you need to use the SAME?


2010/7/21 Giulio Petrucci <[email protected]>

> Hi there,
>
> I'm dealing with an application with a lot of threads: it's not a
> Web/Desktop app, but a sort of Windows service, so it's expected to
> have an "infinite" lifetime.
> Different components need to manipulate data in different threads, at
> the same time. So all the components have to use the same ISession,
> even from different threads.
> Running some tests, I randomly got some random exceptions:
>
> - NHibernate.Exceptions.GenericADOException: could not initialize a
> collection ... System.InvalidOperationException: Index was outside
> bounds of the array
> - NHibernate.ADOException: There was a problem converting an
> IDataReader to NDataReader ---> SYstem.InvalidOperationException:
> Invalid attempt to call MetaData when reder is closed
>
> So I'm wondering: can those exception be caused by the simultaneous
> session access?
> Are there any "best practices" about sessio management in a
> multi-threadedscenario?
> And if I create one session per thread? In this laste case, as some
> instances need to be shared among different components and different
> therads, this would lead those instances to be bound to different
> session objects... and, as far as I remember, it's not possible,
> right?
>
> thanks in advance,
> Giulio
>
> --
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>

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

Reply via email to