 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
0 @( n+ f( X! |* r) U" G$ u基本参数:
+ u* f) t9 T$ G0 ?2 F9 e/ d% tjta | thread | managed | custom.Class. W6 f8 G* _; Z# H- T
主要是配合/ b2 @# N# i. V
SessionFactory.getCurrentSession()
+ {" e7 J$ C$ j6 N" p/ N来用的.7 z' y( `+ ~* g0 I+ \
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
9 B6 t9 e8 Y9 n8 M: uWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:2 W8 w$ Z' O0 S- q: T
context.BeginRequest += OpenSession;* U; h `# `3 C! Z
.Bind(HttpContext.Current, SessionFactory.OpenSession())3 q. `9 p2 \. M* ^7 C8 l) K
- }0 h9 S7 P$ \$ i& L
//do transaction' |7 b% I) m1 r' P8 Q `' U
getCurrentSession().Submit();5 \' E) r. c; u( v4 O
getCurrentSession().RollBack();
0 f7 m7 q- K( _5 K! S...& E: s$ m0 s1 o8 n
Unbind(HttpContext.Current, SessionFactory)
9 z3 ?) k4 }6 Q& n/ i* ?' s
1 r" f# s& x4 ?( k6 Lcontext.EndRequest += CloseSession;: a7 P% V! Z' S7 Q, f- Z& i
! \, |7 P, H( `- O 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|