 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 H- F- n; S8 r
基本参数:
( B) p7 S) z' W5 jjta | thread | managed | custom.Class7 I9 N! w$ t' L7 o/ [) z6 }
主要是配合
8 D5 n- W# r RSessionFactory.getCurrentSession()! g- h8 M& \3 A F6 k# j
来用的.
$ P K+ {2 k: \3 G9 L9 \Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
) q: _% q: }/ R5 ?9 O) DWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
9 W: c1 E- U" S5 l" Tcontext.BeginRequest += OpenSession;
# s7 J* t: D1 B/ |% f8 B2 W.Bind(HttpContext.Current, SessionFactory.OpenSession())1 K8 B/ H' G! Z' \/ v
$ a" R1 M+ W, D% w2 |! M: e
//do transaction% Z" X3 y- {1 z0 Q1 L3 j
getCurrentSession().Submit();9 o/ D. X. a# @1 {- l
getCurrentSession().RollBack();
& s. I; t: ~- q4 o& ?...
# w/ H) E! ?7 f9 Z% k G7 B( OUnbind(HttpContext.Current, SessionFactory)1 i; J, _7 K5 m( O/ F1 v7 c3 l/ I. `
, x3 I# f/ z) ^* G8 U$ @
context.EndRequest += CloseSession;
$ Y/ L" U& F- l
& S; T( }2 k. f W2 p: ~0 o 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|