 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what6 }7 W3 P7 w& D8 ]% W4 f1 P9 H
基本参数:" {/ l9 u( p' g' D8 H
jta | thread | managed | custom.Class6 x/ w) X' I b- _
主要是配合* l$ P& Q! Z+ } r. J. J- \
SessionFactory.getCurrentSession(). v! l: v9 O$ T3 R6 H" U8 S- S% b. a
来用的.
4 O" s8 s2 }- X" |3 s/ V" KThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," E; b. q2 f7 f: u: ~- B: d* o0 }: d
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
7 z4 }* F# S; f- E9 lcontext.BeginRequest += OpenSession;8 Z O6 |; {6 i, G
.Bind(HttpContext.Current, SessionFactory.OpenSession())
3 d; q' S" M$ b: P/ o- W) m( ~, ]
//do transaction
& L; y, R4 `* a3 [$ @2 Q; I+ H* ]getCurrentSession().Submit();
* a: T# A5 D8 \7 W" c, YgetCurrentSession().RollBack();* X: F) E+ e& b4 H. K
...
( `7 } X& J, |" _3 k0 ?Unbind(HttpContext.Current, SessionFactory)
" x6 X x# b& C( P3 E1 k
F6 E6 k% F" [1 F9 T% U7 u0 d8 ccontext.EndRequest += CloseSession;
" L/ {4 A' `1 q$ {: d' K( s8 u
h4 s9 S) b7 y5 W9 P 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|