 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
5 q/ `3 e' Z# o. C基本参数:
( k7 [5 y, q3 {5 I' Y6 p4 Rjta | thread | managed | custom.Class
$ s4 o! }' p' `- q( e) l主要是配合$ A$ D0 N m, A5 l$ [' T
SessionFactory.getCurrentSession()
# n1 p* I" B# j! h+ o( M& X来用的.9 [0 y: i1 X+ j! N0 f3 L
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
2 E$ j6 @1 L& h3 ^Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:3 k, w9 L+ W A" B
context.BeginRequest += OpenSession;
/ @4 r' O+ V# v3 w7 N.Bind(HttpContext.Current, SessionFactory.OpenSession())
6 g$ p" K7 s+ o$ t7 |
- O* [8 G$ G3 H5 }) `/ {//do transaction
, Z, N9 a& w% Q; s9 |6 V4 s! sgetCurrentSession().Submit();
3 N, R: U- O) c0 A) agetCurrentSession().RollBack();
* E5 V; H, U0 n2 j4 ^2 [...* m3 |6 t; y6 E/ d$ p+ a* E
Unbind(HttpContext.Current, SessionFactory)
4 E. ?% c( t2 w. H7 W$ C* R# U9 E% [4 u
context.EndRequest += CloseSession;6 v4 b+ {" i# g& [4 u7 f1 ~$ w9 G8 M
$ k0 b+ s1 {; j& s, j) P
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|