 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( g% w _2 E) }基本参数:+ y; s3 c6 m0 c. x0 h( O& y
jta | thread | managed | custom.Class
* N0 q9 F! |! y主要是配合
! z' \) v2 l* n8 XSessionFactory.getCurrentSession()
' m) Y, N' `. o7 v' R" c2 b来用的.
) |8 D# u# V3 E5 L8 i0 OThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 o2 h2 a1 s" W5 B- N4 @4 i; PWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
H0 o/ I/ i) D3 V4 ocontext.BeginRequest += OpenSession;6 m/ L% g0 K9 O
.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 U( Q* D9 @# |. g5 V1 P) y# l$ ?1 y% h3 }( U, `
//do transaction
* p* y, m d* b3 l K6 IgetCurrentSession().Submit();
$ y8 g* `9 \* i* igetCurrentSession().RollBack();
. s$ [# k$ R$ b' |5 B4 ~.../ V9 W9 {4 b# D( b7 l4 B0 @
Unbind(HttpContext.Current, SessionFactory)
8 n! P" |' |! y; b/ C- |5 Q% P2 P- i* \: r& \
context.EndRequest += CloseSession;
' C" P& C3 }" W! W& V; l2 S: S' l4 y1 d' t
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|