 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
9 ~( h9 [8 h" ] X基本参数:9 L9 O7 O6 B `" d
jta | thread | managed | custom.Class8 }1 ]8 |$ [& Y7 A( \
主要是配合
/ U# O& p9 U; T- u: f) [$ f/ DSessionFactory.getCurrentSession() l' E% b8 H6 y& K
来用的.
# q- T. Z# P& GThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 f' i; k$ N+ H! xWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:; B: _. ]2 @' p2 c9 ?9 Y; ]
context.BeginRequest += OpenSession;
9 k* n+ m& h% O+ r.Bind(HttpContext.Current, SessionFactory.OpenSession()); O( p; h; c! ^- q0 M+ W: p
- ?% w( D7 `" B$ G& c7 Z/ G
//do transaction
7 |. V1 p' V0 a1 Z9 c z$ y. HgetCurrentSession().Submit();
5 q t! ?" y, q. I* |getCurrentSession().RollBack();9 X* d4 y8 L7 I2 R- D
..." [0 }2 \8 {' ]* b5 F& ~
Unbind(HttpContext.Current, SessionFactory)
s% K) t1 S- ~
! l2 Y( l# R, a; G4 o5 ?context.EndRequest += CloseSession;
, Y' j& H. H, T {% K, G1 \7 m0 O5 U& ^- R8 [
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|