 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
% S0 C3 j; P7 p9 ]( b5 _" @4 h基本参数:
; `- U: ?9 x; _3 f- l( z( |4 _jta | thread | managed | custom.Class Q1 r$ R$ y6 F! O* d7 |: L/ \* C9 ~
主要是配合9 O) y, G$ ]# H3 x! v" R+ `* K
SessionFactory.getCurrentSession()
) _5 |7 F; z/ x来用的.
7 b' q: Y; K, q; |5 DThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
. Q9 u3 l3 d. ?2 DWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
( z5 M( X7 X: `, y. c5 scontext.BeginRequest += OpenSession;
; g( \: \, Y# U! l- Z.Bind(HttpContext.Current, SessionFactory.OpenSession())
# b5 `& t( ~* _! o$ Y$ S d c% K
//do transaction" J5 b$ ~7 [5 e4 a" [4 P# l
getCurrentSession().Submit(); t! V8 s) k, t+ h
getCurrentSession().RollBack();
4 D( b9 Q: D+ E' L...
+ b( E8 n- T, f+ H4 w! |* YUnbind(HttpContext.Current, SessionFactory)
0 s( ]: K* C* n7 z
/ ?4 B9 y- u; `context.EndRequest += CloseSession;1 T0 B- N, z7 |- x( _ Z/ G6 m
7 L6 T2 Q+ c# F3 q4 Y f3 D6 ^
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|