 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
. `7 B& e/ _& E7 O! G基本参数:
+ r4 F. G- r$ t: b$ _3 Djta | thread | managed | custom.Class
' m$ ]- [* \! M4 w, m, h. v主要是配合
0 }+ U& e/ q; m2 H) CSessionFactory.getCurrentSession()" u( c' d! u% I3 H- l$ K7 M# m \
来用的.2 U6 t* f% L, u( Y$ W9 f
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,' R/ s# S* v' I# V3 [3 z
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
E5 K( O, G) w# k/ \) T( Pcontext.BeginRequest += OpenSession;
8 g+ ^% F# t2 ~: { h1 u- y# I.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 s) N$ X2 J% M
: }' W2 v7 g1 q! K//do transaction
( S5 p; K$ Q. `getCurrentSession().Submit();: `; u& Y/ k: o; o4 Y
getCurrentSession().RollBack();4 I4 ~& [, ~; X) P2 V5 W
...
# f0 L6 n- u* XUnbind(HttpContext.Current, SessionFactory)/ \9 Q* ~/ {4 I+ A1 T
, D3 ~: c6 W) H6 ?: o, kcontext.EndRequest += CloseSession;
y6 C$ Y' \2 @8 q- H( J3 w3 z. n5 [" q. P% U0 V7 X
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|