 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what. k5 K& k1 r3 X& Z6 a1 R
基本参数:% X- b i$ u$ @5 F& q6 v5 b$ }
jta | thread | managed | custom.Class
( e: ^$ c# E4 s9 [4 t主要是配合
' Z+ Q3 m# J8 A7 rSessionFactory.getCurrentSession()
; O+ g7 i6 t+ M ^8 E7 o来用的.
) H+ r' ]8 y4 SThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,$ k7 q: r! c# Z& h1 h% L: c$ Y
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! Q) J3 P2 S" G4 m! ?! @context.BeginRequest += OpenSession;
; [1 j- ^, ~7 o5 h1 I) D.Bind(HttpContext.Current, SessionFactory.OpenSession()). v( ^/ u2 z! ^
1 \! [% o f2 b; k//do transaction) L3 @# p/ v6 r0 P8 c7 X3 e1 j
getCurrentSession().Submit();1 ?) i1 Q5 ]! G! M M% q2 i9 g9 _
getCurrentSession().RollBack();
/ a8 H1 n- g1 [' m...
7 B! P: e X! ]+ o% l( Z, nUnbind(HttpContext.Current, SessionFactory)% H/ t% g4 D, J5 P
% ?2 E1 _ m9 y1 Ncontext.EndRequest += CloseSession;
. I+ Q4 D) z: p2 h: D
- `) O$ ^* y( g6 b7 P 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|