 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what5 D$ @ c. [7 ^
基本参数:
+ V" S) B# v* U% C' Njta | thread | managed | custom.Class6 ]& |2 z2 r% \' R! f
主要是配合
K. j: r# b0 Y1 i+ f( G3 pSessionFactory.getCurrentSession()
* A8 r/ C& [9 C) x# F& D& Q" U来用的.. z6 T, ^2 {6 S+ b5 _/ s
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
1 e. C2 z# N( c1 Q/ hWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
+ y; T) W3 m* H. [3 Q) y3 Ycontext.BeginRequest += OpenSession;
: `" Y8 ^9 H1 g# h: I.Bind(HttpContext.Current, SessionFactory.OpenSession())" i9 V; O7 H+ B- N$ I' H- b5 \
9 b, }1 c( Q, [8 K. J//do transaction. b) A7 T( b( o
getCurrentSession().Submit();
, e% B! d: Z- n- A: {4 r. o7 jgetCurrentSession().RollBack();
- f& Y& l8 [( ?2 `* u9 L...; N# o- |, J* _
Unbind(HttpContext.Current, SessionFactory): d. j, P5 g( F
" L0 I7 j" V& Z6 _/ ~ X/ |
context.EndRequest += CloseSession;3 i3 m! L: k4 t8 H
{# j& @6 @2 g4 Z3 Y6 L9 d; ]# Y
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|