 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
3 [( `5 r2 h* k3 p8 k基本参数:( O; j( k2 g% Z [- ~) J+ o$ g6 q
jta | thread | managed | custom.Class) \# e! \" `" `$ s
主要是配合9 o6 E# q' ?' B8 V
SessionFactory.getCurrentSession()
+ [5 O% \$ O! }来用的.
7 I; F/ t M$ m8 AThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 C5 Q$ x# p/ _& B( f+ \Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
: S' X7 m) P( y0 s. }8 H0 ycontext.BeginRequest += OpenSession;3 i h1 C! F* f# m; @' E
.Bind(HttpContext.Current, SessionFactory.OpenSession())+ A$ K; z- R, k) p4 f8 p+ _
3 E; [' A$ X0 l7 \/ J4 p6 E/ B//do transaction
/ M+ K# y2 ]) W0 q. n; I7 g, KgetCurrentSession().Submit();: `( I$ t9 m) R' ]9 }% \
getCurrentSession().RollBack();
0 J4 j! ^! U( m3 O! f! }$ T, s...' L2 b' r% Q& V% K6 l
Unbind(HttpContext.Current, SessionFactory)3 `' f2 o+ x. V( J
$ n! E+ i# P' _% p$ e
context.EndRequest += CloseSession;
' }( |8 Y( i2 h
( Z* e) x! j, J1 D; g9 ~1 K; x) R0 N 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|