 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
/ k. G- h$ M( Z基本参数:( @' B- l0 v# v9 z
jta | thread | managed | custom.Class& c- w8 F3 j4 C: t
主要是配合9 M% C l2 f3 \" L$ s
SessionFactory.getCurrentSession()
( j: y1 K) g9 m: t# G" s来用的.
2 T9 S- P U( q( ~' Z: KThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
# N9 W" w+ Q, O% uWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! C; F% a9 e' D+ b5 \6 vcontext.BeginRequest += OpenSession;" g. L4 B, ?0 X. J# x
.Bind(HttpContext.Current, SessionFactory.OpenSession())
' u: O' V6 x7 B# J& A+ `: ]" }
; E2 O8 a% _( L' ?//do transaction
1 T/ I( ~3 m M) ygetCurrentSession().Submit();
6 Z5 z4 p5 q6 h$ Z7 lgetCurrentSession().RollBack();# O, i+ G' L4 l, q' O3 C" C1 L! L; D
...
6 |4 J3 @: v+ |7 r2 t/ UUnbind(HttpContext.Current, SessionFactory)4 }" }. k* `) x) y7 A1 a- J
4 N2 c2 t5 ~, Q$ c; T( Z6 D, \
context.EndRequest += CloseSession;* h, C: N0 P# N& z4 _ E
8 W+ s- r) P; i
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|