 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what7 l5 S6 z3 K9 F0 i* L# m' V
基本参数:
+ |; Z8 c$ {" V: F mjta | thread | managed | custom.Class
: p3 u/ `: n: @2 {5 ?' g$ V主要是配合# ?( r6 }% z5 P2 v1 E
SessionFactory.getCurrentSession()4 |4 W7 x4 I% ^2 |
来用的." [2 h* t- ~4 | ^' P) h) {' W
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," N, |$ {6 N4 Z" p! k7 B
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
6 D" K8 Z# a$ O0 j" ocontext.BeginRequest += OpenSession;
- _0 q4 D3 |8 }- N.Bind(HttpContext.Current, SessionFactory.OpenSession())
9 }- h% F; ^/ f5 i L9 m5 v/ r3 @7 ~# t$ }* q
//do transaction* X' b1 t4 a5 Q i/ Z
getCurrentSession().Submit();
& b" | j& C7 n2 C; W( pgetCurrentSession().RollBack();; y$ {0 D" T) E7 q8 f3 F
...6 x. L" ^* B. w
Unbind(HttpContext.Current, SessionFactory)
- @. L- z' }* x a
1 i X! ~- @( o/ T, X1 Xcontext.EndRequest += CloseSession;( E% Z) ^, d( W0 v$ z
3 z) X) n R2 ]9 t9 ~9 L: V5 x- x 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|