 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
4 x. f8 M8 \+ A基本参数:
6 E, P5 X8 ~% N7 n: v1 Ljta | thread | managed | custom.Class
, Z% {5 |& G3 d) a1 q8 c主要是配合+ Y+ y, |! `( V S6 ]1 b" R" a+ R
SessionFactory.getCurrentSession()
& j+ q. u$ C4 y+ X% q/ e% J* _来用的.
! s& _4 B* A3 _0 n; P" ^ lThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 M% B! X& i, S2 S- V/ GWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 k' g9 s+ G! f- M' _0 k
context.BeginRequest += OpenSession;
# {$ p9 x" L# g.Bind(HttpContext.Current, SessionFactory.OpenSession())2 s. [! l2 c; n" |5 i1 v
7 k& A1 S1 m* F2 U
//do transaction- |1 z. G5 d# m/ K: P7 M
getCurrentSession().Submit();
. D# z) a+ j, n5 F( EgetCurrentSession().RollBack();
, D3 v! d' l, i o0 v; }...6 L7 p# I e& L3 e
Unbind(HttpContext.Current, SessionFactory)/ J2 C3 [' O' Z: P4 [* P1 c7 z7 v
6 n5 W0 |8 e9 }5 t" N: j3 y, ^1 T: bcontext.EndRequest += CloseSession;
9 u% M0 x+ ~9 p- R
: F+ L% M! S' F 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|