 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what0 o1 H- C6 e+ G2 z6 p
基本参数:
# q" N8 c: S! c$ X( r9 d% ijta | thread | managed | custom.Class5 U% h! b, M# q
主要是配合
' W# q. P# x5 c* W# GSessionFactory.getCurrentSession()8 r, r% t/ e) t) D* A0 J/ |
来用的.
) x2 d/ ^/ U: ]) }Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 s% D9 l7 y; ^4 uWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! l" m6 Z) D* n( {( D2 F; L' Jcontext.BeginRequest += OpenSession;
' f8 F$ m, h# t0 D0 M.Bind(HttpContext.Current, SessionFactory.OpenSession())
K& K/ o& T2 i( [' c; s6 U$ o$ L2 |( ^5 G0 j
//do transaction
) G) B- m3 }' ^: [0 FgetCurrentSession().Submit();
% R: w6 r7 j" RgetCurrentSession().RollBack();
! K8 h! ~! s6 Z+ C...1 i& c% o- F! T3 r. {& X U0 C
Unbind(HttpContext.Current, SessionFactory)4 I" e, f6 h# k/ X/ T
% S8 z0 t7 Z4 G; D8 C: @context.EndRequest += CloseSession;& j1 x% C! z. t1 j u
, q/ D, ]- _1 a- b7 s
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|