 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what5 D% P5 P2 E9 q* F/ T8 ~0 ]) V
基本参数:
- V0 }6 e8 X; x, H+ q8 G9 wjta | thread | managed | custom.Class
( p" H' l& x" B6 W5 }主要是配合; s9 d2 m! d* R: s
SessionFactory.getCurrentSession()7 D/ B- I1 H( X6 E; n" i
来用的.' P$ i5 Q; l8 w }$ n; {
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
9 V; t7 p8 o# ?* X1 ^4 t KWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:% u6 W8 V h3 M5 C, [- e
context.BeginRequest += OpenSession;
8 O" L$ C1 L' z. o.Bind(HttpContext.Current, SessionFactory.OpenSession())1 z. x) p+ j: m
6 ~4 y- g4 G% O5 I7 i# ]//do transaction
9 D" J( h2 h' c x# \! ~3 cgetCurrentSession().Submit();7 ~1 m7 S, r$ s( b. c
getCurrentSession().RollBack();
( H: J+ {/ B5 @* q...
! P, v- q( a" M% |- |Unbind(HttpContext.Current, SessionFactory)& w( b, V q& I: S" w/ x
* y3 A/ \9 V9 [. e/ m x/ @context.EndRequest += CloseSession;
) \; ^& U* r! C. I( ~# x. s! N2 c5 } p
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|