 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
_. { Y' u* I# ], I5 q: y基本参数:: D) @. L5 O2 k+ M6 ~
jta | thread | managed | custom.Class R% U7 y3 }" [% _3 O; m' u
主要是配合1 o/ ~) t. M3 L. Q$ `; n. E
SessionFactory.getCurrentSession()
$ N; B3 L/ M! h, B- j来用的.
& ^" T; s1 Z6 Z2 }9 u/ L; i; a2 vThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ K2 ~1 m i. _0 h4 }; t6 H
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
. n0 S0 h+ V1 K$ f- ^& Tcontext.BeginRequest += OpenSession;
: k* E1 ^" J i1 a) a: \- P.Bind(HttpContext.Current, SessionFactory.OpenSession())
8 l- A1 X x) {9 ]- m# C7 I8 z4 S, z, B" F+ F* y
//do transaction0 ]/ ?3 q, U' A! \7 D
getCurrentSession().Submit();
]% y g! m! ?# S. v/ c* [getCurrentSession().RollBack();4 M+ U/ T3 e( r- o0 S! \
...
. h+ z+ l* @4 ~+ @0 d7 NUnbind(HttpContext.Current, SessionFactory)) T# N! G$ k- _9 u" ^. ]) O, B
0 P& g% d6 z$ L& p3 v- J2 m7 o( Rcontext.EndRequest += CloseSession;( S8 V) n; M) x7 M; K
$ t( G' v) C' m$ A, h 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|