 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
0 K/ a e" X6 a$ o基本参数:
- T F- P1 g4 z/ z- I/ o* Vjta | thread | managed | custom.Class
$ N% M2 M+ t" E: r* \主要是配合. T4 C2 E8 X% h& L' G2 { k% \+ @
SessionFactory.getCurrentSession()
; {# I! d( V$ H' V5 ?& ]3 o来用的.
; @3 p9 P7 r( a! w; mThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 p' C6 k, x$ \6 T ^Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:: K4 ?: ^ Q. x$ t7 k- W& B
context.BeginRequest += OpenSession;! B& G: t+ h& L0 `- T
.Bind(HttpContext.Current, SessionFactory.OpenSession())" I1 c9 H% \; I9 r- Y
# y# H4 q' K8 e% E' W6 r//do transaction$ g [! J( `# \) K! B8 F
getCurrentSession().Submit();; [% |! T9 W, e, {2 H0 N) D' f
getCurrentSession().RollBack();
7 U4 g5 ]+ x6 @- _0 I- F...
6 x3 c$ P% b- xUnbind(HttpContext.Current, SessionFactory)- v" a3 z/ P, o% R, Y
; j3 X& q' m, T: |* ]# E
context.EndRequest += CloseSession;: J1 P/ N1 `+ {0 F; G. q
* S! P* e4 ?) I: j0 r; v7 Z7 x
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|