 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what+ V( R( Z p& p( t
基本参数:
0 y2 W7 j/ p! T m% R: ljta | thread | managed | custom.Class
# l7 F- O& F# M! r2 [, q- k主要是配合
6 L6 h0 |; O" iSessionFactory.getCurrentSession()3 T- K' @' C9 w8 K0 j
来用的.
' n H3 M6 A4 ?/ ^& ^! H# j' l. VThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ [( {2 b, j% C' S: {6 _
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:9 N" U0 }6 `' E8 _ A; q
context.BeginRequest += OpenSession;4 v$ O7 N; t8 t1 L- @
.Bind(HttpContext.Current, SessionFactory.OpenSession())
* c1 L0 x* l! w: X: P7 U: X. ?8 i$ O5 I( N3 S$ ~
//do transaction
j: h, U3 y1 K! m0 v& I( h4 fgetCurrentSession().Submit();0 Y( w* ^/ n. w$ n% W- y1 z
getCurrentSession().RollBack();$ a: [* O' U( Y! |
...
, L( M0 ]2 K8 S! P4 G! {, A( @3 _Unbind(HttpContext.Current, SessionFactory). R% w* ~+ C: ]; A% D3 x# q4 l
& E; L9 U: o' h9 Icontext.EndRequest += CloseSession;
, _& b- I; T$ |/ x5 n4 Z9 h
! g2 |* L2 P, @# s& S$ A 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|