 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what0 P) R! V2 m% e5 a
基本参数:1 l* _' `% `/ J4 U! u" }
jta | thread | managed | custom.Class% _; ^* t7 v5 m0 U2 o& U' m
主要是配合' N4 z7 u) r( F: ?3 i
SessionFactory.getCurrentSession(). Y4 T. M8 L, c, Z7 ~: N
来用的.
/ Z# H7 t- g3 l9 x& v9 pThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
( B& l3 q0 U6 I8 ^; V8 f l8 OWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. n/ E7 h* \0 f0 f* a
context.BeginRequest += OpenSession;
1 H4 ^5 y! O, _* Q. ]9 A.Bind(HttpContext.Current, SessionFactory.OpenSession())
h8 p" ^5 B' X" J0 x* x7 k
- C% |4 p d( l+ ]6 O4 V/ X0 j//do transaction* V$ x& L7 j; I- J0 x/ N/ Y
getCurrentSession().Submit();
3 `2 O) i' w( P# h3 r( ? V) _getCurrentSession().RollBack();
) H8 m; |7 i2 ?2 Z; k6 ]# ?...
0 V5 m7 W& Z* bUnbind(HttpContext.Current, SessionFactory)
/ {; N( n4 G& z- h+ E& u
' h+ U1 i/ v2 v7 M9 ^8 {0 [context.EndRequest += CloseSession;' S" P" { ~* g* d, F' s# t6 N: S
* P5 ^3 K( f4 ? 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|