 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what D- |" j% ^6 I, I$ s
基本参数:
' |' s- V5 P4 p8 m) i2 }. v* j% ljta | thread | managed | custom.Class
. y! b9 O8 `/ s* K7 V! l主要是配合1 m) F: g \$ x O9 Y; D+ T
SessionFactory.getCurrentSession(); Z0 E5 X. F0 m
来用的.6 N/ _1 W. G4 u# A0 }
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
- E9 v3 S! B; u/ k& h$ r/ `6 L: i+ WWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
6 ?! ~# n* e4 J8 p$ Ucontext.BeginRequest += OpenSession;
1 M ^9 k# y+ }5 N. O4 h.Bind(HttpContext.Current, SessionFactory.OpenSession())
6 A9 m1 B& L! I8 ?- t
+ z9 i- |; z& A//do transaction
" J; l% y) m* B' EgetCurrentSession().Submit();
( @7 j: O' g- ]* C p7 M5 K- z/ wgetCurrentSession().RollBack();1 X/ ~/ N6 s3 j
.../ ^/ y: p0 [1 W, Y" D' \& S5 z
Unbind(HttpContext.Current, SessionFactory)
! \- i y- p$ D \7 T4 d' Z' B3 r" a3 U$ k+ o
context.EndRequest += CloseSession;
* Y& p8 W/ r( c' G5 ?4 O
' }. s" U& T9 p# u8 s1 C2 H" p! V8 r 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|