 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( a C" z7 X' k$ r基本参数:0 W* M8 l4 ~! Z' ?* u9 h
jta | thread | managed | custom.Class b, a9 n& L8 f
主要是配合8 i4 }( _8 l5 r7 W& Y# i: p" C
SessionFactory.getCurrentSession()( S& t7 q5 Y6 z/ Q7 Y) `, u
来用的.
! n+ `: J6 S7 Q8 B6 cThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
0 m& i3 f% A1 }& j: u4 P4 B# \5 _6 U- QWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
$ ?8 ?4 I# \+ v; N2 H1 fcontext.BeginRequest += OpenSession;) e4 D ]4 D8 Y/ t0 f
.Bind(HttpContext.Current, SessionFactory.OpenSession())) z6 @2 e' o$ V6 @- ^
1 W, g ?$ O) ^ F& J3 o9 l//do transaction$ a; I- c" P8 H, o* Z
getCurrentSession().Submit();
6 }& x- J @1 P, ], Y+ p5 kgetCurrentSession().RollBack();( S1 X( L8 u8 Q- a$ l% P
...
4 G3 u& \1 }' pUnbind(HttpContext.Current, SessionFactory)
) I4 j8 `$ ?$ D1 G9 N
% N. _& L2 o3 r( \! P7 ]! \7 wcontext.EndRequest += CloseSession;
, n( M) {& p# I' }! s, o3 o8 d* W
1 n1 ^& X4 Q; j% o1 b0 s2 N 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|