 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
/ H) I6 I6 j+ n基本参数:
3 o" \5 G7 H- K- g- [% \5 R2 qjta | thread | managed | custom.Class3 b: Y' |1 A$ Y! Y4 @' c
主要是配合
/ h, U \! q: Q+ x) DSessionFactory.getCurrentSession(): M0 U9 Y. ^+ h1 q! O, b
来用的.! y& L' e6 X% I# i
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
( l! x% L4 G. EWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
6 L) v3 I% Y. G0 I3 d0 f8 N. {context.BeginRequest += OpenSession;& s3 y- k; w4 t$ R, r
.Bind(HttpContext.Current, SessionFactory.OpenSession())
5 x& v2 W; T u6 o" j4 w( I3 d- P# t1 R- C
//do transaction! {1 p& E/ @+ E# N5 K a* _
getCurrentSession().Submit();
7 K1 F. U8 p: D6 ^. m; `getCurrentSession().RollBack();; d" u/ L3 Z4 Z( ~& W
...
$ s! S7 B! _% ^9 z* y3 M3 KUnbind(HttpContext.Current, SessionFactory)
; h; C3 }8 |0 Y$ m M4 |& ~ ~: e2 v$ p- |2 j
context.EndRequest += CloseSession;6 Y$ K! |( h* t- |2 O( A
3 C* q" n: _4 ]2 M, {
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|