 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
5 F& V) K, }. {# o6 a! l- _基本参数:
4 m T4 |% B8 a$ }- ~jta | thread | managed | custom.Class e+ j( m1 ]' E) K, D3 M1 g8 z
主要是配合
& j: _; N6 u, CSessionFactory.getCurrentSession()& b* Z3 w5 C, J" ?/ \
来用的.6 c" S' R! n" r; M
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 |& `7 m" {$ C* S2 c; aWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
) w, {% ?1 O' b) G) a; x) bcontext.BeginRequest += OpenSession;
1 C2 ]# l5 `7 c6 I& f.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 I$ a6 K* b+ e4 h: J, m! V+ h# t3 z" D
//do transaction
' d4 {; @) ]" M$ t& H+ @0 l! i" T) ^getCurrentSession().Submit();
5 T; |4 d+ N/ y/ F+ M: `; @getCurrentSession().RollBack();
8 ]8 o* x) E+ t9 b...2 F! ^- Q. f( B9 l6 V7 |+ [/ a# @; g8 _
Unbind(HttpContext.Current, SessionFactory)5 a3 [5 `, ]0 {/ P4 c
; R+ V! T# n h, o% t
context.EndRequest += CloseSession;) F c! n1 F) u, N# F0 Q
6 I8 q8 R1 Z3 U$ p W! B4 y# M 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|