 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what0 M) X. x& U2 G
基本参数:; b) G, Z7 }+ v; C, _0 W3 }6 @
jta | thread | managed | custom.Class
& g; O# x% Z5 ^ W7 \主要是配合# K4 L0 P1 g( X, w
SessionFactory.getCurrentSession()" Z& B# Y+ R4 `7 B3 x, Y- U
来用的.4 d8 h. U Z9 M# w: x# q6 ^
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
, @9 r' s) {2 H0 }4 R: rWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:$ \6 s, A5 i9 p
context.BeginRequest += OpenSession;
+ Q1 d; p9 D7 Q8 B. y# {/ v( G.Bind(HttpContext.Current, SessionFactory.OpenSession())& v( s: b0 Q, Q8 \7 x
; y) [, |* h6 F# g
//do transaction
& M- a% @$ M. |1 n9 `" i! [getCurrentSession().Submit();
% T: L2 x7 m Z% L% Y3 O9 \getCurrentSession().RollBack();
# i M, t0 h7 `- x' M& z2 n...
# s" n+ U$ E6 H5 |: DUnbind(HttpContext.Current, SessionFactory)
& g, e, q' w9 ?6 K( v0 R
4 Z* m, L& e c1 i( G# gcontext.EndRequest += CloseSession;
/ v m! x. x' H8 M( D
% i5 V' t o$ s- h 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|