 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what2 D3 s$ A& ^5 n/ V* u' J- O x
基本参数:
2 a. ]3 ]$ p0 U/ l$ x C5 Mjta | thread | managed | custom.Class! h8 C' c8 \: t4 @
主要是配合0 D3 ?& Q& h6 n4 w9 P; _- a0 C5 o
SessionFactory.getCurrentSession(), E1 T' K* F, d& @. B$ F
来用的.$ I0 i' V) D6 X2 \: Q m$ ]
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,7 l: _, O% k/ b1 z+ M5 S4 u: w
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
. m O) F9 ]. G$ Scontext.BeginRequest += OpenSession;
2 R( M8 Z2 J s.Bind(HttpContext.Current, SessionFactory.OpenSession())# K. u# v! h& k+ U* D4 C, i
3 q/ Y0 j) L- e* n4 U2 [//do transaction" W2 g" M( t. P, ^" d3 b% j! z7 S/ a* _
getCurrentSession().Submit();0 a& o- O: l& x2 }$ k) s y: V4 v
getCurrentSession().RollBack();
. u1 V1 i# [; f4 b5 [ R% s' |.../ E- L# N0 K! Y P
Unbind(HttpContext.Current, SessionFactory)1 U' M( r( p! p* @) |" y K \; W
+ ?& D' Q: ]/ F/ N
context.EndRequest += CloseSession;
+ y5 @- @- N2 i2 z. i6 R2 a7 Z1 A7 |: @9 h
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|