 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what5 ?' u% ^1 w0 J: f2 b: o% Z4 A
基本参数:
; ]* }% d. U9 P% _/ Zjta | thread | managed | custom.Class
7 ~" t, x3 e- l' d. ?) |5 P主要是配合. i4 i3 U m, v' j3 F2 ^$ ~
SessionFactory.getCurrentSession()' ?# n- W$ E' k& Q/ b' t
来用的.
/ V- T6 q* u2 _8 p1 `8 j1 M( P: gThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 O* U! o2 [4 B9 o( ?% | lWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
6 d1 X Q5 Z6 n8 O; Ucontext.BeginRequest += OpenSession;9 h L) G, v" k1 l9 `* i% a
.Bind(HttpContext.Current, SessionFactory.OpenSession())
# s/ ?' M7 l/ }/ I5 ~$ q7 Q# g7 R% _, }2 D0 t0 x9 V0 Q+ \/ L& Z
//do transaction+ m8 o* h: D. d& I
getCurrentSession().Submit();
" d5 u9 l8 c- z# X+ S* OgetCurrentSession().RollBack(); V% A5 @! m3 w" k8 W& g! D
...) @! v5 z/ P2 R9 m
Unbind(HttpContext.Current, SessionFactory)) U# h/ N3 p: y) A* O
4 l! e$ F0 R* G o& H9 S9 A% zcontext.EndRequest += CloseSession;
8 T! Q1 ?5 k/ Z F* d' w
) w1 u* @; X. \/ d8 [% f$ X1 ? 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|