 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
! y6 g# ^8 ^1 M: W8 G) c基本参数:
" d* }: w$ p0 Q) t* B$ S+ v5 Mjta | thread | managed | custom.Class
( W) z* a! [' i' n& s主要是配合
* j$ E. Q, [5 ]0 RSessionFactory.getCurrentSession()
! `; i$ v: m' j3 u来用的.8 ^+ i- X9 V% f& t3 H
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,* [6 |! u6 c( U0 C) @8 U
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如: D6 X9 K! j" n+ Y( Z
context.BeginRequest += OpenSession;
* j D% Y' E9 w) u5 Y.Bind(HttpContext.Current, SessionFactory.OpenSession())
3 _ j0 \# S1 W W, x) N) K1 X. [' Z8 i6 a) c
//do transaction) @: x2 A' h3 v1 v
getCurrentSession().Submit();
, B5 U; P7 D3 D8 ?getCurrentSession().RollBack();& d e) Z" {4 [" f" D
...9 [0 Q: ?8 I' |+ S9 {
Unbind(HttpContext.Current, SessionFactory)
9 Y: d& G2 I' Z% H. S8 f/ V, p, K3 o& F. x
context.EndRequest += CloseSession;2 y4 k$ X6 M5 V) S+ J
: {: B. ^% F# w7 ?, O2 ?" p. Y 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|