 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
$ ^! T, c5 Z& N6 v4 n基本参数:
0 M, ?8 n" W1 ?4 L7 |jta | thread | managed | custom.Class7 _# A( n. `( ?
主要是配合
& k* O$ z/ v. ~( q, o: j! ISessionFactory.getCurrentSession()" L, \3 w: C/ \7 p4 F
来用的.' d2 f/ x; z4 f+ z
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,- i) G& G. [* Z+ |0 _
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
?; W& [/ R3 \1 S( xcontext.BeginRequest += OpenSession;
k" [0 q: G1 ^0 s. g.Bind(HttpContext.Current, SessionFactory.OpenSession())
: v& Z( q" I3 \6 V. ?6 r: l) @7 }3 y
//do transaction
: N* o( ?/ q4 h8 |) x" J) \3 `1 n* igetCurrentSession().Submit();
2 ]. q, p! N8 M" X5 ygetCurrentSession().RollBack();+ U8 H( `1 v: Y% ]( p9 N' i' k
...
a* J/ N- i: ^+ a: `# fUnbind(HttpContext.Current, SessionFactory)" l; Q% h; Y9 p2 Z7 i9 E# h( _
# ~* g# R O+ ?1 G0 {" mcontext.EndRequest += CloseSession;
! }# ^2 s/ f2 p0 M* c- ^' Q" w% ?9 ~; h
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|