 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
7 N- c. Q, }+ q4 J3 K2 E基本参数:2 i$ i5 t! ^+ w/ }- y( d$ d
jta | thread | managed | custom.Class2 B- K ?$ T" H6 `/ z
主要是配合
# O: M& Q% H4 ~, i g+ c' ISessionFactory.getCurrentSession()
$ g1 i7 C2 Y* `5 q0 P$ |, D% T来用的.. v# T P# ~, X/ [7 ^6 t- e
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
5 j0 T: v/ A3 X9 a& |5 pWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 L9 l2 _- C+ S3 P3 x1 \context.BeginRequest += OpenSession;
Y" j f. k# \8 V# K.Bind(HttpContext.Current, SessionFactory.OpenSession())- S4 G- E( I% Y- R7 \1 j
& T! z8 b, {; ~5 Z//do transaction; n7 p% l) G! @5 O3 Z
getCurrentSession().Submit();
& o! }' S6 ^0 H+ U4 r& `/ a g+ X; cgetCurrentSession().RollBack();
" I( D" P8 n( K9 `8 W$ z* i...
' n; s, I" i$ U9 `Unbind(HttpContext.Current, SessionFactory)
& ~+ J! H( k2 }' h
* ^6 t u* ?! }context.EndRequest += CloseSession;
* e( E+ y, P# ^+ D5 F: I4 U1 F- R2 K8 C8 @3 B a
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|