 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
: E {2 `: v' }, W基本参数:
, y, n( X b( O) i7 gjta | thread | managed | custom.Class
1 g3 p* P# r7 w主要是配合
2 `6 ]& d2 z' U Q& z- q( |SessionFactory.getCurrentSession()" C+ b5 ]& ~; ^, I
来用的.
+ x0 L& L8 p; F5 ^) S4 sThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
0 D; s5 u2 H, [7 f# K6 ]Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
# a# `2 Z X* x+ tcontext.BeginRequest += OpenSession;
) y, @& I# h: p" ?8 t.Bind(HttpContext.Current, SessionFactory.OpenSession())
1 r) k4 y! H7 v, a1 P2 D8 n7 {2 Z! _( k5 O9 J1 L2 i
//do transaction3 e( K" p/ s5 n- H+ h4 c
getCurrentSession().Submit();9 ~% p7 O4 o0 p3 l% d- W( a
getCurrentSession().RollBack();
; e6 u8 m3 r3 ~...
: I" R8 s% |- m& f& d( p( sUnbind(HttpContext.Current, SessionFactory)$ s8 [5 x7 C3 B. X) x- h
0 |! t! O" x- X0 q; k/ ?( Dcontext.EndRequest += CloseSession;9 o4 E% T! R7 f
% a4 Q4 d0 J3 x3 N: A, ?) n 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|