 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
- o; D$ t y* W* N/ M& R; W6 F- M基本参数:
: c7 X7 U: F# O5 ?( Gjta | thread | managed | custom.Class: E+ @6 j! P; o
主要是配合' {0 B% s, P6 `
SessionFactory.getCurrentSession()6 `$ k8 r/ @8 Q
来用的.
6 S# Q& A( j. y. x& A, I, ?Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 Z8 @5 w, |( Y pWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
4 K5 k* H: z4 Z( g0 C: v2 _( Icontext.BeginRequest += OpenSession;3 r2 t* T* h- b* U& v1 R1 w
.Bind(HttpContext.Current, SessionFactory.OpenSession())7 C# J+ ^2 \1 I( \9 h
4 S" H/ F: K* ?$ u6 M! Q1 J//do transaction
& c( d3 B4 v( C2 k. I* sgetCurrentSession().Submit();
7 k- X q' m* V3 i" U; c$ vgetCurrentSession().RollBack();
" ?4 Y0 x/ W1 P6 } x3 i...
# w7 s3 \: \# S. }% Q kUnbind(HttpContext.Current, SessionFactory)+ z- j: C. z" l3 K B
1 ?3 K4 p" k$ W1 ]' k# I$ V5 F; Vcontext.EndRequest += CloseSession;
1 u! ?1 O# l9 Q% l# J* }* Z( b1 m" c
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|