c# - Spring.Net / NHibernate - Multi Threading -
i'm using spring .net , fluent nhibernate in window application, , i'm working multiple threads. read in blogs , questions there can 1 session per thread, , i'm using hibernatedaosupport , currentsession it:
public class daobase<t> : hibernatedaosupport, idaobase<t> { protected isession currentsession { { return sessionfactoryutils.getsession(hibernatetemplate.sessionfactory, true); } } }
however, testing feature , must show sessions of each thread different sessions. how can it?
obs: after research found objects obtained through nhibernate session, can not changed in session, example, can not find object in "session 1" , give update on same object in "session 2". but, in tests i'm getting object first thread , updating same in second thread, working. whats wrong?
you've got backwards - thread can have how many nhibernate sessions likes. important thing session not designed threadsafe, 1 thread @ time can operate on particular session.
until session has been disposed, operating on object loaded session counts "working session", since may trigger lazy loads etc. objects loaded still-active session should accessed single thread @ time.
as violation of thread-safety rules, there no guarantee break. there no promise work either.
your test can have each thread access currentsession, , put instance in shared collection, test runner thread can access collection of sessions , verify elements in collection distinct instances.
Comments
Post a Comment