 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
; N% g; ~, i1 x+ I# ~2 V! F基本参数:7 x) S8 K) {/ Z
jta | thread | managed | custom.Class5 a l4 Z8 H* }
主要是配合
9 c% a$ ~! u, e' I5 PSessionFactory.getCurrentSession()
& g2 ~" J$ v( T6 D. ?' t来用的.! `4 c: l6 B8 h
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
$ d: Y. t* C4 {# EWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
/ J( h0 \# ^: x/ U1 fcontext.BeginRequest += OpenSession;
- ]4 e+ @7 W+ [: s$ f+ z0 b% z7 @.Bind(HttpContext.Current, SessionFactory.OpenSession())4 o) g* w' V N& |- F1 r
2 X, w$ J# H0 l, M* b
//do transaction$ Y" [% }3 J6 ]1 \% Q' g
getCurrentSession().Submit();
2 e3 o8 S6 P X ygetCurrentSession().RollBack();
" Q- |! y' w* ~...
0 K) {/ |7 } QUnbind(HttpContext.Current, SessionFactory)
4 T, ?; |& m# l& b( L! i$ l) p! D1 e' a/ j! z- C
context.EndRequest += CloseSession;& r+ b& L1 L5 b8 {/ V
`% X$ _) r$ `# G! f# @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|