 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( Y9 K+ f1 W& h* l$ U$ W基本参数:$ m4 o! p4 C( T7 m2 C% Z( ^
jta | thread | managed | custom.Class8 E0 e# U" L, }" [
主要是配合/ t: b% D' Z# Z( Z0 k
SessionFactory.getCurrentSession()1 Q! k! O2 t4 b$ p
来用的.
1 h; ?& c4 n) S: I+ Y( BThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,: l, {& W2 o- G: B
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 J# W! q5 R2 y. [% C
context.BeginRequest += OpenSession;
' d% j2 b) a& N# y# f4 x9 i.Bind(HttpContext.Current, SessionFactory.OpenSession())' n5 V' _2 j+ L( y+ P8 f( J
. Z1 n$ p* P$ D/ h- H4 T& I; e9 b//do transaction
: U7 h! C, _0 _* E) J" FgetCurrentSession().Submit();
+ W! |9 m2 Q3 P: h' p" a' y% bgetCurrentSession().RollBack();
( ]; [. r6 S# `1 ^" i...
; Y. o+ e' N, s; o! Y8 YUnbind(HttpContext.Current, SessionFactory)9 z/ t8 i/ e1 B! y5 G
8 f+ i0 k q2 ~/ J- E6 mcontext.EndRequest += CloseSession;$ g0 _: f$ l; ?* U5 ~2 T. A0 H8 c. I
8 C" S" q1 @7 E. P7 D0 S1 q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|