Nhibernate 的手册里这么讲:Never create more than one concurrent ISession or ITransaction instance per database connection. Be extremely careful when creating more than one ISession per database per transaction. The ISession itself keeps track of updates made to loaded objects, so a different ISession might see stale data. The ISession is not threadsafe! Never access the same ISession in two concurrent threads. An ISession is usually only a single unit-of-work!这里面有两点:
1,Session不是线程安全的,所以不能在同多个线程里使用同一Session。
2,一个数据库连接使用一个Session。
针对第2点,一般会用单例模式实现。这样的话就有问题了,难道所有的Session操作就只能在同一线程里,多线程就只能用于非数据库操作上吗?
如果有哪位知道如何突破这种限制,请不吝赐教,有实例更好,谢谢。