 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
9 A' C/ m3 A# \; F+ [% r, a* L基本参数:
+ F9 Y2 G5 T& h+ Vjta | thread | managed | custom.Class9 x7 d! B# V& o" ?, ^/ e
主要是配合& `# |" z* q7 m5 }5 T( ?! _) H' D
SessionFactory.getCurrentSession()
/ ?8 D$ T+ H- P+ S, p来用的.
^. ~1 t% K) @9 eThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,8 `7 F1 u4 l B0 H
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 I& C4 n2 I: M
context.BeginRequest += OpenSession;
! Q2 D( L# x2 {0 O.Bind(HttpContext.Current, SessionFactory.OpenSession())
4 j3 L0 N- t' C6 M; K" h9 D
- B# D2 A% l3 @2 g5 d//do transaction" ]+ C3 d: D- F2 n2 P7 C
getCurrentSession().Submit();
4 X! Z( v9 [$ q/ v2 EgetCurrentSession().RollBack();, E/ W6 ~- Y6 c: g
...
$ ^9 }+ i- ^3 [6 ^Unbind(HttpContext.Current, SessionFactory)
4 Y$ T/ N+ \: ~: B
- a' E) r" n& v5 Y) n& h6 c* jcontext.EndRequest += CloseSession;; F% L: e$ O6 y5 s/ q/ _" c) Y
7 P8 A0 w! L5 ^: h0 o( U5 S3 e! i 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|