 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
# e- [. o' O+ b6 g: r基本参数:' O1 V- s6 t/ |2 A9 ?2 j) h/ b3 q, @
jta | thread | managed | custom.Class
9 F! q) ?$ A+ c0 @主要是配合
5 y7 B7 d4 Z d% n0 OSessionFactory.getCurrentSession()
8 A7 x7 ]+ O: H0 A0 r+ M4 n来用的.9 j3 J& Y6 c J5 s; `$ }, O y2 r3 N
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," T" w. @+ {" | V
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:# z( L; x, J1 `' D s0 X8 x
context.BeginRequest += OpenSession;2 ^6 X) u" K2 f0 }& R3 B1 s
.Bind(HttpContext.Current, SessionFactory.OpenSession())
& D0 i: V! H) M2 d! }$ H6 J. ~; o3 c. ~# a- p: h' \
//do transaction5 ~, _, G6 k: D+ R& x y( D4 s
getCurrentSession().Submit();4 c" f1 Y. y# p5 m6 P# ^6 d. w
getCurrentSession().RollBack();9 F) ]% M6 N6 }; I& N+ |5 x
...0 O: ]5 A$ H) L7 y/ Q+ D3 e
Unbind(HttpContext.Current, SessionFactory)! a$ e! k3 _" {7 i) A8 E
/ E& R$ F* D* L% D5 I* K: g# icontext.EndRequest += CloseSession;4 U) m8 Q/ B( M" ]0 V$ h
9 I- Q) S) \' B$ ^ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|