 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what: ]* f7 `9 H6 H" k( B) x$ c
基本参数:- E3 @2 L" i3 V! ?; ]* C# B5 ^
jta | thread | managed | custom.Class+ w8 ^& j5 _+ F) f
主要是配合
7 T8 N7 s' E( p2 A1 }2 s: pSessionFactory.getCurrentSession()
9 H+ \& u* r' Q$ Q6 O+ {! w9 U来用的.2 j% Y% X; ^- B* A
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
/ v; m$ F, L$ @+ `* T/ HWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
$ G; [. a- `6 V' x9 W. ncontext.BeginRequest += OpenSession;% S4 v9 h3 c+ P) V5 Y# H7 _
.Bind(HttpContext.Current, SessionFactory.OpenSession())* X8 w% U0 W" t3 g7 D+ G
0 y0 ^! x9 v, p0 x& N//do transaction
: i% q5 r* h$ l& M' i. j, |% IgetCurrentSession().Submit();
' W" J4 I2 }0 ]. QgetCurrentSession().RollBack();
0 p. [$ i7 @& C) C& s% I$ S...
9 H& d. d( }/ V3 g$ U1 hUnbind(HttpContext.Current, SessionFactory)
y: J& r4 Y6 r$ @/ A9 h' n$ I2 K9 I1 I* E g
context.EndRequest += CloseSession;0 {7 g, P1 A( r. _& [% K
0 J5 `! f' L m 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|