 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
, |& u3 a0 w1 F基本参数:
" R8 j; j2 }' Ijta | thread | managed | custom.Class/ c' w8 \) L( b6 K% u- ?- X
主要是配合$ F' U) q- i) e/ T) v
SessionFactory.getCurrentSession()
! k2 M) k$ D0 m/ v+ c2 y来用的.. N8 L0 b( Q9 Q" x- ]
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
2 e9 D' M5 x8 h( oWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:) ?- p7 q9 E. j6 g
context.BeginRequest += OpenSession;
4 D9 T4 i/ g' ?7 Z+ H.Bind(HttpContext.Current, SessionFactory.OpenSession())/ R; Q# @/ J7 N" m: d
4 D" h4 U1 n, S8 Z//do transaction
# Y% S- V+ Y. W, V/ p4 p6 x5 y- tgetCurrentSession().Submit();
7 `8 b) [, y: GgetCurrentSession().RollBack();
& M, i; d- J0 L( u...: |" M% j2 i8 b! h& @
Unbind(HttpContext.Current, SessionFactory): Z- U4 r' u5 G) O- H' g1 Y
0 g' L8 T3 m* h O% n3 l
context.EndRequest += CloseSession;; I% `5 _3 A- W, W1 x
4 W ~& C E+ @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|