 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what2 j+ {- [$ \, G2 m7 E, H c) q" `
基本参数:3 F( J7 n# }9 {+ d% Q! f5 V% K
jta | thread | managed | custom.Class' K, \& e/ }2 `. X. Y0 Q& E" ^
主要是配合3 o) e3 R5 H4 Y! ~# {
SessionFactory.getCurrentSession()
T0 r2 H$ Z- _9 q' v/ v/ H来用的.$ a e; P1 D. J: c/ {4 j: b
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
! M/ t* ]: h+ x, w4 h3 A2 qWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
+ X; w4 J* y/ }* D7 t7 gcontext.BeginRequest += OpenSession;' S3 n! s3 l: N9 M
.Bind(HttpContext.Current, SessionFactory.OpenSession()), c6 a: z) o( U: M
! e0 l9 o1 z& B
//do transaction9 g7 E* u6 U3 q+ G$ M# N
getCurrentSession().Submit();
9 v; z' J0 I: p' UgetCurrentSession().RollBack();
8 F7 t" K9 c4 E" T, l: f+ m...
3 G* m- W" B( }0 OUnbind(HttpContext.Current, SessionFactory)
/ o" l! b9 h! {) a( o9 o8 D: k5 x: C& K& b4 a# z
context.EndRequest += CloseSession;1 h: D8 }, o" o1 _3 E0 {
; [" u0 b2 D4 O) m! m& ~ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|