 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what) X+ B5 \! j" J) M, J4 ]$ `
基本参数:0 `9 P5 n: t: V; G
jta | thread | managed | custom.Class
# f6 e# `4 J9 X, v6 \主要是配合
# A: L4 z' j% j' q. G9 e7 GSessionFactory.getCurrentSession()
& }/ `2 I! S$ k5 W- J来用的.' j' A9 j1 s8 p+ q( }4 ]6 G' D2 D
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,5 @; T: k# e4 X
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:2 t q) f: N ]+ ?1 }4 i
context.BeginRequest += OpenSession;
) q# K7 S) V% t/ q1 H.Bind(HttpContext.Current, SessionFactory.OpenSession())8 L% ^" Y; n# W" f) C3 s1 p
0 h Y& \- n8 o+ x//do transaction2 B) I5 `. U) E m& h. Z
getCurrentSession().Submit();. Q9 P- |2 u5 D& k3 ]# I5 c
getCurrentSession().RollBack();
7 H' Q9 r& I0 t1 {( `...
; f- W+ I. x/ i9 ]Unbind(HttpContext.Current, SessionFactory)
. J M/ ?4 u4 f! t4 o) ~! z j
6 t/ R9 v) M. o1 T! \context.EndRequest += CloseSession;
4 i2 @8 Q$ _1 K% }1 G6 Y. a
. g; D) `" v7 b+ ~8 b+ G 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|