 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
8 H4 e" X. v6 G. k3 o$ Y+ o4 L基本参数:0 t1 X0 Q! p) _& O" v
jta | thread | managed | custom.Class% f# S4 X* ~4 w! V) E* U
主要是配合! Z# a# D& O/ C8 f" u( A
SessionFactory.getCurrentSession()
9 M, K% e0 A# ]% v s* Z来用的., L* B0 _/ B' {7 A8 O/ ^4 z& n
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
O& B8 B5 i4 Z- F# h- HWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:$ n* q0 z$ ~ C4 A2 f" o
context.BeginRequest += OpenSession;
0 x; P5 j2 x* W, g3 R.Bind(HttpContext.Current, SessionFactory.OpenSession())
2 o @* J ^) Y& @) d: R; h" p: ?! I. v6 D9 P; \7 c- B
//do transaction
7 b- P5 |8 G# ggetCurrentSession().Submit();
6 E* d" V5 e$ A2 b/ m3 `) OgetCurrentSession().RollBack();$ S" K7 _* t& ~ s1 b3 n; V
...
( [, e! X0 \6 Y0 N9 n% ZUnbind(HttpContext.Current, SessionFactory)9 p. v& c# G2 d- K) Q. i E
; S7 T% Q# n% h- W
context.EndRequest += CloseSession;% q3 a) S) ?4 x1 a1 _4 c
& x7 ^0 `% b+ [% ~) z" C8 v" V
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|