 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what1 R3 Q- E6 o( K+ M& i$ u% x) L* W
基本参数: u0 j" B7 l: S% n; l, m1 }! O
jta | thread | managed | custom.Class
7 C! T. h& H2 ?9 V: ?主要是配合
( \$ D( l# D0 w+ u( C4 k4 A- ASessionFactory.getCurrentSession()$ r3 `3 i) R/ a* l3 y
来用的.6 {) E8 g5 N0 ]% n
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 _' b5 o) a0 v/ u8 \% J3 qWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:3 o6 ~# q4 m! B: L
context.BeginRequest += OpenSession;
/ }% C( d# i& R! S2 p5 S4 W* l.Bind(HttpContext.Current, SessionFactory.OpenSession())
4 I, W8 y2 g7 D9 p p G. N* J
$ ]8 \! u9 @$ L9 i//do transaction" K" z# q2 R3 A- A# n- V
getCurrentSession().Submit();
" \* ]: i1 M& }getCurrentSession().RollBack();
& W4 T( _6 O* d6 [...
, F8 |; {3 C) I# \$ \; [Unbind(HttpContext.Current, SessionFactory)6 m: o/ h0 J' \3 n" c. E
+ \% E" F0 O7 v; B6 k% M& mcontext.EndRequest += CloseSession;# o5 U, g3 W2 }% ~( Y- W% ?2 H2 X6 J
* _1 H" c' z% ~% L+ N
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|