 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
/ G5 a! j C; F+ R9 W基本参数:
6 _6 t* B, s8 ojta | thread | managed | custom.Class
2 f7 e# O. `0 \# o2 e( ]/ l主要是配合% Q) ~; M. w' T5 H7 ?" z
SessionFactory.getCurrentSession()! t) a8 w( u8 Z0 I5 ?- W
来用的.
& R" o8 J( d# a& eThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
5 v; ^, b7 l( zWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
- A/ e5 c; ~7 p% J+ L% Hcontext.BeginRequest += OpenSession;+ S; d( Z0 r" t* J( t; p0 S# [: g4 L
.Bind(HttpContext.Current, SessionFactory.OpenSession())
: i' ?2 o j+ E( P) S2 |# M, D5 B& ` i6 t( h7 E X: _" X
//do transaction4 ?; m6 Y6 k9 L% a Z5 }* K0 E
getCurrentSession().Submit();
0 D- [# d0 Z; i! H. L/ }# v( g" WgetCurrentSession().RollBack();
" E4 K( l2 G% S0 [' w6 C3 }5 O) |$ ^5 M1 j...
4 h: _- P8 w! |+ nUnbind(HttpContext.Current, SessionFactory)
& K* v; f5 |& ]" n1 Y+ x8 _8 a" f* D: c! B2 Q. W/ E; f
context.EndRequest += CloseSession;
/ Q1 V+ W) G) U5 H9 s9 c5 _. D$ d5 f+ l# J4 j) n
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|