 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
2 | S6 V t# I% P( B `) }5 A基本参数:
3 c* l8 H1 r1 G8 i* B, e6 ljta | thread | managed | custom.Class0 @# |- r" u$ F) m
主要是配合; e2 ^* t' O8 l6 v4 I& Q
SessionFactory.getCurrentSession()
# a* L% `: j, e+ E2 ~来用的.
$ I8 o( F b( q% I/ c/ AThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 b+ U M; U5 K& j7 S* M! A* qWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:6 @% Q+ a$ c5 o3 X/ w7 e
context.BeginRequest += OpenSession;( t7 `/ C/ Z9 B ?
.Bind(HttpContext.Current, SessionFactory.OpenSession())
' Y- D @( c/ D w2 b
( s- D* T; C$ F M8 q//do transaction
9 V# o) F$ W: tgetCurrentSession().Submit();
: U+ Z( u3 X' YgetCurrentSession().RollBack();' ^' H5 _0 c% B5 `" s1 e( w! h
...
' o: s5 X+ L6 o) ~( h# a: L5 uUnbind(HttpContext.Current, SessionFactory)
. }% \& M0 a) d" j; K8 I4 }* N, O7 ?" q6 f& C% z) ^3 o0 W5 r
context.EndRequest += CloseSession;
+ D" C+ v6 a7 h6 C$ q" o* K" Z+ |3 z, v" d# @) Z! f1 ?
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|