 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what: m8 }) E" b3 W7 o' h6 [# K5 t3 `
基本参数:& |# g) P, K1 @7 S' v9 S
jta | thread | managed | custom.Class
, D& T6 a* {. t9 i1 q) P' V* v5 B主要是配合
/ n% z' M4 t, c& |( \3 W. q+ dSessionFactory.getCurrentSession()
, c( T- J @3 n Y( e& S来用的.+ l! N" j/ \4 @& M! w5 u% ^
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
% M/ }+ e" i+ g7 v+ ~( k) LWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:& a! Y" `7 S( S4 T# {: i! \
context.BeginRequest += OpenSession;3 j+ O2 E) F; P; K
.Bind(HttpContext.Current, SessionFactory.OpenSession()) u# @* T4 q; d! K
/ {3 o+ ]& X L2 b8 q8 L//do transaction
3 w; F2 k8 f9 h4 a# {) K e' Z0 vgetCurrentSession().Submit();
5 W! D. z9 y% R; KgetCurrentSession().RollBack();
% e# |' {: X7 u1 h...
- y" i( y, n/ a. c7 D/ b( t# zUnbind(HttpContext.Current, SessionFactory)! _4 y. \2 _0 `) W# l% v
6 j" d6 t: e8 X! w: A, Dcontext.EndRequest += CloseSession;
# o" b4 N# x8 l* X6 [+ B+ T' Z5 f1 H+ ]/ X$ z: t
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|