 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what4 k: ]: g0 b% i
基本参数:. P. Z/ v( u5 p: @: O* B" x% C8 N
jta | thread | managed | custom.Class
. p2 g9 O+ f5 b! y: E6 N8 K- E主要是配合0 z$ W+ I6 V5 ]+ H2 f t
SessionFactory.getCurrentSession(): k( w1 y- ]" j+ [# l& ^
来用的.
r3 ~# b; h) I5 l# fThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 f3 e5 n$ t9 H& P5 s) o8 MWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
6 z: s+ I( x6 P1 M% w) W7 ~$ P% Hcontext.BeginRequest += OpenSession;' d1 j; i7 q2 A+ R6 a" w
.Bind(HttpContext.Current, SessionFactory.OpenSession())$ K7 J$ T- T- G& B$ d
% b3 G/ U: n Y( T% r. f0 G" i
//do transaction* K) w+ Z" k! @. f
getCurrentSession().Submit();2 L( Z: y; T1 n4 [
getCurrentSession().RollBack();6 G) [, {. y- s" i) i' _, f
...9 ]2 z0 u& m$ ?
Unbind(HttpContext.Current, SessionFactory); V9 i! `1 l6 F1 ]5 n
% I3 k% j# Z1 u4 H1 econtext.EndRequest += CloseSession;
: D/ P5 N8 {+ A/ _7 ~2 }: N1 \
7 m7 T& t# Y6 H; ~ q( ] 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|