 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
) O6 s( Y/ D4 \5 R$ K# L& e基本参数:0 P* D! B% _2 g2 u9 W! X
jta | thread | managed | custom.Class
. Z7 f. Q) R R9 i1 V" L主要是配合
. F' g8 d% a2 e0 O- w' a4 w/ kSessionFactory.getCurrentSession()
# G% B0 {/ c% S4 [/ o/ |7 T @2 B e来用的." f( l+ X" u q a& ^+ ~, q( B
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 y( p5 t! i; y: bWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
* @0 x+ f4 `( zcontext.BeginRequest += OpenSession;# ^: D5 Q$ J# y! ~
.Bind(HttpContext.Current, SessionFactory.OpenSession())) v4 b- b* x' F0 [! U i
& r: Y X" k1 E2 J Y//do transaction3 |& G+ \$ q0 u& |- M# \
getCurrentSession().Submit();
( W% C# t; J Q& tgetCurrentSession().RollBack();
6 W \* O# |# t. w...* a+ ?/ n- G8 l8 u' C0 v$ J x
Unbind(HttpContext.Current, SessionFactory)
: h' P& D# f# E; v& ?9 g8 i1 r* o* X! T! B8 X" d# B
context.EndRequest += CloseSession;' [. V, T N; _- z' k/ L, l
1 u# u9 n* V+ s" G/ \! J
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|