 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what G/ U+ ^# x5 L3 E& S+ t8 r3 I
基本参数:
, n! ~$ H: S" @5 v* Ejta | thread | managed | custom.Class0 H# S0 G/ u/ ^) l
主要是配合6 r) V8 E) Q/ W' [4 ?; c6 a
SessionFactory.getCurrentSession()
6 Q! J2 k. Q# m* p5 R% R- K来用的.) B+ X( @% w. k, Q, m/ ]! d/ D. ~
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
& M& N- T, j9 T5 y% Q( Y& \Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
+ K+ k" Q5 i. \* }9 Z( acontext.BeginRequest += OpenSession;( C3 s, d( R) a
.Bind(HttpContext.Current, SessionFactory.OpenSession())# b& s/ r* I. f; y! P
2 B( I* N0 q+ a7 k* r2 h//do transaction! |' l4 S9 N* K: L$ b- f
getCurrentSession().Submit();
5 I8 X+ q5 a2 t; L, WgetCurrentSession().RollBack();
& ] L3 t8 x* a2 T...
+ r6 N q+ c0 a$ ]0 G9 _7 g% CUnbind(HttpContext.Current, SessionFactory)
. b$ f! u0 P4 B% g f5 t, V/ U' r
- B3 l9 x. K7 y) `context.EndRequest += CloseSession;$ K( N" |' m3 g. G
; I; h: w5 ]4 N# e 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|