 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 Q5 e- j8 K) ]8 N0 i e
基本参数:; Q2 U7 A. E3 _, W
jta | thread | managed | custom.Class
1 l$ i' n5 n; C9 l, Y主要是配合$ G3 k0 \$ ~, U# j3 `
SessionFactory.getCurrentSession(); N. `9 z+ }: {/ `0 F
来用的.
6 X' [/ h0 t( ^+ z' ZThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,5 r, k2 T/ \4 ?$ `
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:: o6 F" `" N- ~4 X7 Q( c
context.BeginRequest += OpenSession;
3 w9 t# I9 P3 E7 L.Bind(HttpContext.Current, SessionFactory.OpenSession())3 x. a6 ~' V! I C6 O: |; H) Z& f8 g# x
9 D! ]- ^$ ?2 [//do transaction1 K/ r! p/ z: M: K% |% S
getCurrentSession().Submit();
$ [. N6 c7 `7 T: |getCurrentSession().RollBack();8 |7 E$ H7 e- M6 i, m# D$ S
...+ W: ^3 M% _* z B
Unbind(HttpContext.Current, SessionFactory)
, l7 B8 O2 L" e5 n0 M; P( t! F7 V. P$ x- |0 \: x A8 P
context.EndRequest += CloseSession;8 q: b0 [3 l4 P: n2 Z# d
/ l, U, K7 ?, |5 o4 ^8 I! z! {+ p 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|