 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
# C" H# A) C) T$ M7 ?基本参数:0 ]( \) f" W" G/ b7 d- T* x
jta | thread | managed | custom.Class; r. [( c# o$ p B- W
主要是配合$ |+ j1 M$ e$ Q) J
SessionFactory.getCurrentSession()
, M5 F4 N% D" j8 ?, J来用的.
4 I, o9 g" I* v& |Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,6 z# h5 L- i& h2 W* v2 R& v' K) R
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
- r7 d9 |( R7 [9 E! N7 vcontext.BeginRequest += OpenSession;
) z+ e; d/ C% z: j2 b8 a) u+ \5 @ i.Bind(HttpContext.Current, SessionFactory.OpenSession())
) f; \, T5 L; E2 |* e6 g
6 o' C1 J2 @; c1 p//do transaction6 I% ^8 [, V2 }* j2 X& z: t
getCurrentSession().Submit();
2 @; D3 _* C. x: @getCurrentSession().RollBack();
' |! ~9 X, \) a# J k! A...: g# r6 \ }6 e; p" [: R" h
Unbind(HttpContext.Current, SessionFactory)! p( Z0 M7 I0 _8 w+ J
s; B* {: o" U9 g# |2 Vcontext.EndRequest += CloseSession;
8 K( [% `1 f/ Y9 b4 V% ]. C6 r; j% D+ w. ]( m2 b: y: F
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|