 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what/ f& a, U" c" [! k$ R* M) v
基本参数:
) y. R; N# C3 \8 S$ f* ojta | thread | managed | custom.Class/ l0 F9 C5 I6 I, B8 }
主要是配合
$ Y2 x5 Z% ~. j6 F# K1 s; m5 VSessionFactory.getCurrentSession()# t) ^; o' {; \
来用的.
6 K+ q' K/ q* \6 GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
- I J" R/ T7 Z+ F% mWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:1 F# \5 S8 K8 H+ B# T C4 f
context.BeginRequest += OpenSession;
! N g6 G( M9 v% \6 ].Bind(HttpContext.Current, SessionFactory.OpenSession())% ^* g( R- W* L" C
G- h6 d+ }/ W" B9 [# O
//do transaction. K. o& Y- q7 s$ s- J8 ^
getCurrentSession().Submit();
; P# v5 h7 W4 H# ]- u- HgetCurrentSession().RollBack();
4 B% z! }1 c" ~/ u% r! M( c...* E1 A7 V$ O. h. @7 A" H1 c
Unbind(HttpContext.Current, SessionFactory)$ u$ O3 \$ D l
! ^: O: u* n" _- r9 c( L6 p$ E
context.EndRequest += CloseSession;
2 P( f: `: @( r2 H, |: Q* _# k- `! @+ T9 L/ j4 ?) \7 b
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|