 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
, V9 q# e) `# B, A8 r& `基本参数:! J" Y, `: w/ Z( d0 A# C; Z
jta | thread | managed | custom.Class( ?5 Z7 V6 c9 c7 y! _7 W. Z
主要是配合: S$ y0 d) J* H$ Z5 d: r
SessionFactory.getCurrentSession()
% ^' k, N. Q) k; q' n) k+ f8 _来用的.- m( Z" l+ r! ~: c
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
+ u% m' H @$ ~7 L- OWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 F4 Z3 R' [) X, Pcontext.BeginRequest += OpenSession;
" w8 E* M. @8 n2 P" n& c.Bind(HttpContext.Current, SessionFactory.OpenSession())* j8 Q; V+ T2 A! ]! x' V1 h1 z
8 y; G q- }- W! s
//do transaction0 X# q$ O3 `. ?7 q; h/ K9 B9 F, z$ m
getCurrentSession().Submit();
" e- I: U3 c3 h3 ggetCurrentSession().RollBack();8 D- A' U7 k6 D1 x3 V1 |
.... K6 H& N5 A" O; Q7 K
Unbind(HttpContext.Current, SessionFactory), Q. E" d& |+ }9 h7 Z ~" W! Z, E
' h: V7 `# y( k) Y) c Pcontext.EndRequest += CloseSession; K" G( B0 K* X
q& A6 {7 F% N: v% X0 W2 c 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|