 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
# U: {3 f6 T* w% S; }9 U3 A基本参数:% S2 o# [ ]. F1 h" u
jta | thread | managed | custom.Class
1 H- U5 q. x1 O# ^+ y主要是配合
2 E/ ]1 p5 U8 @8 c# vSessionFactory.getCurrentSession()( G. T5 ?* h2 F) |& o
来用的.# W2 W: I6 ^. l
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 o v! l5 f; O& \Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
$ i3 d1 J( T4 R) y4 J, bcontext.BeginRequest += OpenSession;
6 ?4 |0 v% h2 j2 E& l' H.Bind(HttpContext.Current, SessionFactory.OpenSession())
* Z$ C( L# S* n2 {# J6 M4 d& Y! C
$ S5 i% O% z7 g% p//do transaction5 ` x% }8 D0 X9 [
getCurrentSession().Submit();
3 X& K" q) E' ~" PgetCurrentSession().RollBack();1 K$ [ i. D: U( Z& K# a
...% G/ D9 B$ Q4 W0 z
Unbind(HttpContext.Current, SessionFactory)
7 \' e- u6 W5 y, c
A9 d( W& e, Ccontext.EndRequest += CloseSession;) a; e2 b* f- q! u# m
. n! m% T( S3 d. x* a 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|