 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
8 Q0 U# `$ s, I+ N基本参数:6 z, N$ o5 x" b2 X) W6 q' _: t7 D
jta | thread | managed | custom.Class" r' F! u4 O( N3 N7 g
主要是配合
1 T- r6 H$ `- l, pSessionFactory.getCurrentSession() k) G/ u% }3 u
来用的.
/ h6 ], a8 ^1 c7 l' e0 G6 ? aThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
# [& Z, S6 v- P8 i" iWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
0 m: r* _$ u- N. E0 O/ B/ f2 Ccontext.BeginRequest += OpenSession;3 f. I: e r; ~2 {
.Bind(HttpContext.Current, SessionFactory.OpenSession()): ]; M5 h+ o4 Q" w: X i8 t
" m4 c, v) u+ E/ \6 w5 p
//do transaction. J6 N( Z* F- e9 M% \, Q& i/ c
getCurrentSession().Submit();
2 X7 ?; }4 f, c0 w7 ugetCurrentSession().RollBack();* B/ ?) H- W& [' f8 q9 Y
.../ B4 U# q. E' ^& v
Unbind(HttpContext.Current, SessionFactory)( i2 |/ P. @7 J
w5 H( u0 z; m( m2 p" j/ E1 gcontext.EndRequest += CloseSession;: X# N( M; c2 ?+ I" b( [
7 H2 h6 f& g# @& ~" k7 H 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|