 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
) \0 i' G- A3 r5 A% N基本参数:
) K2 d# V% {/ K! \( @jta | thread | managed | custom.Class. |8 b! J8 d6 Y3 _5 c% V7 z
主要是配合
! s6 l }$ p0 A1 i& E% e3 j5 q" ESessionFactory.getCurrentSession(). T+ V; Z# V/ i: ^: `+ G6 R
来用的.3 x+ ~+ y0 i* u! Y
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 \2 l& g# h7 |% v" I- `; ~' NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:, h5 z- |9 k7 G2 f4 R5 B
context.BeginRequest += OpenSession;0 s7 I' n+ l, } o. p
.Bind(HttpContext.Current, SessionFactory.OpenSession()). ]# L. D7 b/ V* P
' x8 E: m, C* q+ F+ n- t; b* f
//do transaction" M5 S; k# a7 i. s$ f: e i
getCurrentSession().Submit();" R O, s; ?5 H; G
getCurrentSession().RollBack();; A% \) n1 \: P
...
6 ?( b9 O& S& N- o( A9 \: y0 hUnbind(HttpContext.Current, SessionFactory). ~" \2 z* e( c6 W
6 K( f( v/ P7 ?$ W* Fcontext.EndRequest += CloseSession;- Q* d9 z( M0 ^( e
6 q, ~; b0 h4 n) V2 a6 L+ ]' A: l
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|