 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
/ b9 I* T1 t: p, B: e基本参数:; v/ y p' l" Q$ Y0 V% a; j
jta | thread | managed | custom.Class8 j. I5 B* n1 t: l2 J0 `
主要是配合
- u* ~3 a$ D0 h6 P3 e! p2 L, kSessionFactory.getCurrentSession()
3 J+ _4 l2 J4 R N5 }来用的./ r: k, {, @6 @2 W$ u# S
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,& A4 d' E7 ]6 V/ ~$ _
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
7 V% \% F; j0 t" F- B* Econtext.BeginRequest += OpenSession;
% G, H- f$ F) f.Bind(HttpContext.Current, SessionFactory.OpenSession())6 C: @0 c n: o* L
# B- Y2 g: a ^5 ~- s( x* Z7 A
//do transaction( D. h6 U/ Y! L
getCurrentSession().Submit();
, C. x- B- t2 X# T E2 JgetCurrentSession().RollBack();9 s5 [0 E( E: B7 y8 v% H$ i
...
- P* Y) o' ^& X2 U& }8 UUnbind(HttpContext.Current, SessionFactory)
2 w D$ M3 T9 w5 K- A7 b- Q/ o- [7 V0 a
context.EndRequest += CloseSession; O9 |' W$ {0 t7 y( ^, M
7 N1 ?0 L8 Q+ R 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|