 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
8 \) V, y1 Q1 u8 p. Q基本参数:
: m; g, @- ]: A1 ~! ? m+ f/ L1 Mjta | thread | managed | custom.Class
/ c6 B2 v8 }) ?7 {主要是配合
: i# N6 z9 h5 f$ N- V7 M& U7 `SessionFactory.getCurrentSession()+ u' @0 |3 W% u7 v
来用的.
! k( Q1 e% @; w" D3 w( `" qThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,3 k$ p1 w8 Z. P4 u) D$ n- q4 @6 C
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 w0 U' f9 y; C5 Z
context.BeginRequest += OpenSession;
a; \4 p" {6 g- ~9 F H.Bind(HttpContext.Current, SessionFactory.OpenSession())
" P4 E3 W) @7 e$ P1 G0 _2 {6 W% b
' k8 z& J0 P# \- i! q# \" ?: t- n//do transaction0 w( p! K' C! ^! g, p& B. U
getCurrentSession().Submit();% s* p& g4 C* M* Y4 ~5 C1 i- s
getCurrentSession().RollBack();( A* `0 ?! V# e( ]" `6 e7 {
...
+ {& ~* G, y3 x7 M5 M# s! uUnbind(HttpContext.Current, SessionFactory)) s, `& d# v) x9 C+ g1 ?0 g8 `
. k2 b6 Y. v1 o% u% k
context.EndRequest += CloseSession;
) _+ Z, ~0 F1 g( b* {! B0 m# H7 C: R% q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|