 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
9 f3 _& W: j5 p1 a) k6 c' |基本参数:+ N" v+ b3 Y8 s: Y. n# c4 Y8 e
jta | thread | managed | custom.Class- r+ }. U6 w+ @: e' O
主要是配合
1 E9 V9 ^2 L. X4 w% p8 CSessionFactory.getCurrentSession()* H) ^. Q/ I9 q3 A7 j
来用的.$ O" G4 F) y/ W& {( C1 D
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,( L8 o1 R5 v' H3 b. y9 @5 c0 n
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 y$ Y( Q# l& O/ ] q0 o( g) vcontext.BeginRequest += OpenSession;
8 h3 u% C& m) i" l. j.Bind(HttpContext.Current, SessionFactory.OpenSession())3 G2 W3 S% l+ ^: }
- E6 ^) J F+ Q; y2 J! w//do transaction
- [" O A' F, O: B# Q2 ]getCurrentSession().Submit();+ p3 n" ^( g8 U1 h3 z; G4 U& F
getCurrentSession().RollBack();
* {; Y. V7 x8 q$ d7 M5 Q...
/ W* z- C3 p, O; D) pUnbind(HttpContext.Current, SessionFactory)
0 ]1 B W3 A- d& v @* q5 z# j5 g1 u+ n9 Q6 Y
context.EndRequest += CloseSession;
; R1 j8 T V8 o& P K T. _6 t7 V. i, D! E& H
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|