 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
8 z- t( k/ R" c! [# f- ?8 z* N; T M基本参数:# V# v$ ]8 T$ C2 K2 _
jta | thread | managed | custom.Class) _& b0 R2 L7 C
主要是配合, N; X7 |0 \: d$ g
SessionFactory.getCurrentSession()0 i' A8 s9 S6 P, e' {+ R
来用的.* d3 v, a$ S) e6 L* [- x
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
1 U# G2 b( ] E. B" `Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. q" a; L3 _: \% b V
context.BeginRequest += OpenSession;+ u A: z7 k6 H7 x4 I9 S9 U9 ]
.Bind(HttpContext.Current, SessionFactory.OpenSession())
' V2 T3 ~, N4 D% j! m* {5 P
4 z E1 D4 X- w/ q//do transaction+ T7 o* A+ D. f9 L# y
getCurrentSession().Submit();/ ^6 Q( ~7 x/ a5 j
getCurrentSession().RollBack();. b7 t0 W3 R+ X" i* k# B0 I- A/ H- e
...
0 L& p8 O& |- d. ?" u2 F+ U: j$ R2 KUnbind(HttpContext.Current, SessionFactory)' a1 `1 t- g _* F
# ? ^1 q! ~8 Y# j* K/ b( Y
context.EndRequest += CloseSession;
5 S, E7 t# O( B+ L9 H; J, y8 j
) I) M, t+ J! u) V( U( U9 Y. v* [ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|