 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
2 h7 W- A% @0 [4 W7 E基本参数:
3 [. k0 b0 j, C! i4 fjta | thread | managed | custom.Class" }) u! J3 c: q) F
主要是配合
% D( X! q5 x0 ]# D6 b# _0 JSessionFactory.getCurrentSession()
* O' u5 [6 C6 O6 S/ ^来用的.$ {0 P" s: j( i+ R2 A l6 ~
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 I. x% i+ H5 B$ _& e' g( d1 k( y2 DWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:5 ~1 K5 D8 A, s
context.BeginRequest += OpenSession;
4 ~, ~* W/ q* y3 w+ @.Bind(HttpContext.Current, SessionFactory.OpenSession())0 w h! ^1 R. q. q% U) o
0 Y" f. V- E3 t6 F( I/ G3 i! T
//do transaction
( S- ^2 R1 k0 d% G4 L DgetCurrentSession().Submit();
2 {6 y+ L# y. V( P6 n0 OgetCurrentSession().RollBack();
( X9 y8 ^' _+ k9 a: @( A- x6 A...
/ h. K7 @3 S% r% y. E5 WUnbind(HttpContext.Current, SessionFactory)
8 R, @1 K5 W1 g9 Z- ^- K6 w! @$ D9 ]7 B8 W& M/ Q0 U
context.EndRequest += CloseSession;" ?' M9 Q0 C3 X8 t
$ @7 H. ^5 X7 L: P2 X' f' _
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|