 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what
( ^- I& C0 g; S; t5 T基本参数:, _5 T% Y$ Z+ J
jta | thread | managed | custom.Class8 g8 M/ d) p: b) g+ r
主要是配合& \" Y, E4 ~0 M! y
SessionFactory.getCurrentSession(): P# k8 s n4 N [; ^ j
来用的.
g( h: _( F5 S; T& P; U* u6 K6 MThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
* P8 G" M+ D( Q1 n8 U3 nWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:7 p( p7 D2 D6 j; K. ~
context.BeginRequest += OpenSession;+ s& L0 o) l& Y; V) J
.Bind(HttpContext.Current, SessionFactory.OpenSession())
2 Q' [# f+ |$ _3 B& {) O' O$ g2 w
//do transaction$ `( z7 i$ W+ G; H0 y7 ~6 Y. Q8 R4 B- L
getCurrentSession().Submit();
) X* v2 E, I2 F3 }& R! l8 K) lgetCurrentSession().RollBack();; e, f- o3 D1 }$ L5 d
...5 [+ Z7 v7 y& x/ u# x
Unbind(HttpContext.Current, SessionFactory)6 Y6 I7 P' o5 t. J/ v8 X
+ m+ N0 N. b! b7 t+ a' p q9 y3 a
context.EndRequest += CloseSession;& c; ?4 ~; f1 T+ I
& v. H# Q" s0 B% J" o 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|