 鲜花( 2)  鸡蛋( 0)
|
current_session_context_class 主要是用来配置当前 data transaction session bind to what* K# E2 o7 l, e% r
基本参数:9 z# [: e3 g+ {0 z4 ^/ c
jta | thread | managed | custom.Class
# d0 s) ?7 E) n5 V$ D" B: @主要是配合
. Y. e3 Y# w" `: BSessionFactory.getCurrentSession(); D/ d* r% Q6 r G% k' ~
来用的.
/ M; G: k% v* m9 eThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
6 A+ w/ h( g8 F$ M' d; aWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:5 @1 L2 t% y/ {$ ~- a1 x
context.BeginRequest += OpenSession;4 W& `4 `1 Z% F+ F% y
.Bind(HttpContext.Current, SessionFactory.OpenSession())
9 I6 F1 {6 ]# V; Y+ T
; M2 L9 ^9 T8 `0 E! M0 n k//do transaction+ j2 |& L9 { v9 E) ]9 a
getCurrentSession().Submit();1 _( j5 ~0 N# g. p
getCurrentSession().RollBack();
# i/ x# i& {! p7 L...: D/ s! M4 v. `
Unbind(HttpContext.Current, SessionFactory); W# c7 c9 T0 d/ c( F& N! y+ O) E
& A* G* k9 u: h# `) h3 jcontext.EndRequest += CloseSession;
/ E/ u- T$ ]/ \" P( i
/ n: I1 B8 \% D# k/ F 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。 |
|