 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
: o8 S) x& |7 G基本参数: w \( W# l8 A
jta | thread | managed | custom.Class2 D% x& j" L! {2 p2 H
主要是配合, Q) d* R! g; ~9 i$ l: ?5 P
SessionFactory.getCurrentSession()4 n9 A. Z$ M9 L3 K
来用的.
1 ^# i. G' N! xThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
& ]; {5 R1 \3 j4 DWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
* j2 G1 l; ]5 @3 H3 Qcontext.BeginRequest += OpenSession;
5 T2 z9 W- N& Y' q. H.Bind(HttpContext.Current, SessionFactory.OpenSession())8 x. U: r" {/ r/ _0 j1 n
" v% c7 q1 z; S: s; j# z//do transaction$ `5 H1 K o9 e9 N: ]$ |
getCurrentSession().Submit();
/ m& f8 f% @' l n$ ?7 pgetCurrentSession().RollBack();7 B* H8 @1 `$ [! ?, w$ W: O* L
...
9 b* Q. E3 b2 ], }6 n# HUnbind(HttpContext.Current, SessionFactory)) ]0 Y' ~5 R+ S* I% w& Z
" ~% Q2 ]/ |, X8 t) scontext.EndRequest += CloseSession;- r# u2 w8 D1 a( D/ Y
! s( j7 X9 g+ W' L
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|