埃德蒙顿华人社区-Edmonton China

 找回密码
 注册
查看: 1037|回复: 4

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?, g, \2 Q2 s) R% ~0 s
$ _& Z6 Z! }/ Y4 ]* U- _# t# o
谢谢
1 {1 q6 \  d3 Q- ]0 E2 p1 h: t3 `( F  Q* T; j: o) h2 P
<property name="current_session_context_class">web</property>
: t$ ^3 ?) K( r, {7 @' }" c<property name="current_session_context_class">call</property>
* o8 t0 X. S7 |7 g+ f/ a" b<property name="current_session_context_class">Thread_static</property>
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 20:52 | 显示全部楼层
自己顶一下,等高手出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-14 20:56 | 显示全部楼层
本帖最后由 gamahu 于 2011-7-14 22:47 编辑 5 `3 p1 O8 @4 O" j) K( Q

2 Z1 j2 m9 V* F( f! kPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf$ ?* r* l0 O& ~4 d% `  Y

7 M  m7 t5 Q( r. N/ Y0 q+ ?8 f/ u8 H4 Y5 K& e0 z
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf: k$ k: \0 n7 |# |
6 S1 ]7 v7 Q: U6 J- Z
. k8 F% r' q7 k, G* F/ _
Chapter 2.5 Contextual Sessions4 n% t+ z0 E4 u  K
gamahu 发表于 2011-7-14 21:56

# p! t3 X5 H0 ?
% f1 G1 k3 f7 C. J谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.! `8 Z" }, _- k4 B

' ?2 N/ @5 \; o8 R9 W( N8 }& S: X现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what
2 d5 x) X- v4 d/ Z基本参数:. z. F* t' s/ I) y' O. F. D
jta | thread | managed | custom.Class, t8 Y2 O1 w: _7 W
主要是配合0 G! j6 a5 ?7 V+ W7 l% Y! w, v) l
SessionFactory.getCurrentSession()/ c; h- ~# _, K* l$ B7 O" O
来用的.
( k  Z3 c. k: B5 O8 a; p% s  `Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% T) X' ?1 F3 y  e
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
3 j2 a4 e9 b: T7 p2 x* G5 X# ycontext.BeginRequest += OpenSession;. I4 j% p$ c1 X( O% W3 }
.Bind(HttpContext.Current, SessionFactory.OpenSession())( ~& N  V/ D( p2 o& w; K9 Y: A
% R6 V4 _+ c+ J7 d" N- i6 l3 M. g
//do transaction
: O! G; b& c1 V( f. bgetCurrentSession().Submit();$ V) S# V2 }7 F( o5 u& _0 _
getCurrentSession().RollBack();% W1 [7 C  @1 D
...
6 p% X9 j- l3 M" ~) mUnbind(HttpContext.Current, SessionFactory)
: ?0 B) K/ g" b* o2 h$ u6 Q' w3 V7 s% `7 q. e  t
context.EndRequest += CloseSession;
/ u# n& F! Y8 R( [) ?- z2 T7 R, V5 j, c' G$ p+ b
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系我们|小黑屋|手机版|Archiver|埃德蒙顿中文网

GMT-7, 2026-3-4 20:17 , Processed in 0.141579 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表