 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what, B0 n7 ?9 a% [1 }1 v* P
基本参数:
4 I& V! _0 J1 fjta | thread | managed | custom.Class# Y4 B/ J- k/ G$ L( s
主要是配合
) j. d" d: R' jSessionFactory.getCurrentSession()
8 I+ Q# w0 l$ z( s来用的.1 ^6 C) }& o: n/ L) g, y
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 _5 T2 i( `. c3 n5 t4 s B' ]/ M+ XWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
3 r7 A+ o. C0 z& t& l/ I: H3 _' ^context.BeginRequest += OpenSession;
9 R& v/ x! \) d. Q" M.Bind(HttpContext.Current, SessionFactory.OpenSession())
( b4 m4 f. \6 m3 q0 a+ N! L' L. i* W$ B; f
//do transaction- f/ ] a& d7 b8 a! R) u' q
getCurrentSession().Submit();
% N2 o0 e, J& ugetCurrentSession().RollBack();9 x2 z: M2 S1 w# _5 m1 n" T0 J: R2 Q
..." _6 {+ F+ t# D
Unbind(HttpContext.Current, SessionFactory)* N4 \5 D S. R# y. H7 C3 X
; v) y0 N+ r2 C. {( T. q, g
context.EndRequest += CloseSession;
7 X8 N' W6 H. r( d& R8 H0 ~6 o+ w6 O. [5 {$ q, i" I2 o0 L& U5 h4 R7 c, u
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|