 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
8 ^3 W$ h5 j J0 F/ F! U: O基本参数:1 b+ _) s5 E1 y
jta | thread | managed | custom.Class
+ Z0 ^" ]0 ^4 d, G8 o; E# I主要是配合
: R1 ^! U5 s9 v# oSessionFactory.getCurrentSession()
/ I4 G3 n, p$ H( u来用的.
' |7 h) l4 R0 s6 q5 |6 d2 B: CThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,: W1 b" t( [* n: y) R7 H
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:1 E( ?; J1 F. {# \/ _( |
context.BeginRequest += OpenSession;- [& n; I! N. P6 {- n5 r8 y
.Bind(HttpContext.Current, SessionFactory.OpenSession())
# y5 y( Q" w0 v0 \1 u, Q
, E9 D; m. `) Y, h: ^//do transaction* {( V: Z" Q& W3 Z9 r/ T( N
getCurrentSession().Submit(); ~9 i5 l+ J8 G
getCurrentSession().RollBack();
5 a2 L' x$ e" s% [6 _5 B, N8 [...2 N3 w0 i- D' r$ W8 n; W
Unbind(HttpContext.Current, SessionFactory)
+ S% ?$ N4 P: o6 [) q2 @) k! N
. \" K& r% C, c% x9 econtext.EndRequest += CloseSession;. G/ }. K; |" g9 k
) b! Y5 X5 F* n' e1 d# F7 M: w8 L
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|