 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what; H6 E$ ]* L3 ^
基本参数:3 z* Y" _0 O+ E/ ?( g& G$ L
jta | thread | managed | custom.Class
3 u7 `5 N; {( v! m& X4 F( O, t主要是配合
7 z; h$ `) z- i1 ~9 T% YSessionFactory.getCurrentSession()
% e8 ~4 U) C C; J, q1 w2 N" T% Q来用的.. L- r7 b/ q- s, k/ H! ]6 i
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
: N7 r# A) R$ A8 {) l: V* NWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
( A. L ~# u# Qcontext.BeginRequest += OpenSession;5 C7 w9 P0 q9 F! Y* z
.Bind(HttpContext.Current, SessionFactory.OpenSession()) F2 n3 c2 F7 f! Y4 x
( V/ w; j& M* r% O, t) f//do transaction+ R: k5 T. y+ {/ b
getCurrentSession().Submit();( G. p! K9 o4 l1 T/ t* N8 C
getCurrentSession().RollBack();
7 L2 N1 n3 b: }...
+ s: n( | C6 A, f# X2 G8 I+ e9 mUnbind(HttpContext.Current, SessionFactory)
0 h- d9 e5 c, H, W
% Z& Y& [& \7 k- c7 c4 Jcontext.EndRequest += CloseSession;
! k- i6 Q+ D9 \& ?2 x# Z1 I3 Y1 [! o: ]# U- q4 ~" F% _
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|