 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what, p. J3 b7 G. b& h; k# q
基本参数:3 T T E0 Z$ `6 h+ u2 ?6 P
jta | thread | managed | custom.Class
3 R7 _$ v+ F5 I/ V% r) \% L主要是配合2 ^& t: F+ \) e* C/ j1 H
SessionFactory.getCurrentSession()0 N. C, n$ G. n6 z* Q0 c: H: z% P2 g( z) F
来用的.
' F1 R* p. q% KThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 P/ k; ^. J2 G$ M3 R R) sWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:& V- ~! C s$ s) m
context.BeginRequest += OpenSession;
1 L" l( b$ d: `, Q1 w. B.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 m9 y" a; E( y. x. E
5 M# S% q! O0 T2 D% E! q//do transaction
5 L6 z8 U. o% x0 e* VgetCurrentSession().Submit();
5 Z$ v- S: j: b: g3 IgetCurrentSession().RollBack();
' d- Y( \+ B( u) N2 c...0 j# N2 P' ^7 @, x4 p' m& K
Unbind(HttpContext.Current, SessionFactory)% A7 [4 m: t- k
- {) c: L# q k! W% Ycontext.EndRequest += CloseSession;
0 v* L% _: E! Z. B
7 _1 @- b; l* i$ p# d3 v 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|