 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what$ l4 r- Z; i9 K b+ i( I
基本参数:
5 i2 u, r* J/ e: G3 o1 Zjta | thread | managed | custom.Class
G# q7 S9 y9 G6 r) `3 O主要是配合0 X$ Z" l- M; m/ ^
SessionFactory.getCurrentSession()# G I2 h/ O: j4 _' M
来用的./ \) G7 P/ }) _- {5 A
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
# n2 f# F% J" {# h( j% v0 k8 QWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
7 K) R* W0 a$ j9 ?1 ~) Rcontext.BeginRequest += OpenSession;
1 f4 S: s7 c& B' w K: r. a.Bind(HttpContext.Current, SessionFactory.OpenSession())& R% E& W9 B; r# I! h+ y. J4 v% D
$ m+ H `9 k1 @, X" b/ I
//do transaction* v4 n$ h6 P" j
getCurrentSession().Submit();
: ~6 b1 t; l' a& ?1 \7 N1 xgetCurrentSession().RollBack();
) v- P4 s6 T4 H4 o...
9 o9 e$ I+ M1 N3 Y: qUnbind(HttpContext.Current, SessionFactory) p0 m/ F Q% f, ^ I/ G+ X
7 B1 b. s, R: C4 v* ?
context.EndRequest += CloseSession;
9 X) {* V y, D' U, X. ]" D7 V- B. ]
+ l4 G( K8 W5 @; y4 t) ^: f 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|