埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
3 L2 @2 p4 L. A8 @' v$ y
9 a2 a. O' ^' b7 J- m, _谢谢  T$ G6 g: R3 }. z5 a" V
4 z, U& Z6 b) E6 d
<property name="current_session_context_class">web</property>& `! ^) {  q" ~6 \! D7 C& w4 G- M
<property name="current_session_context_class">call</property>" `# b- W* i" k
<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 编辑 ) o* q6 r) B; L5 S* P" B5 d
9 d% ]& k, p8 |  p( N2 _/ e
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf% y1 R9 B; `5 N' M

& j" @% ^5 }4 B+ [
4 h3 r* [4 ]. o+ T+ A% I0 eChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf. D, }! \2 q' ?% w- b# z  f2 H2 g, v

/ F8 M3 v; ?  q. N9 r/ ]# |8 K8 E0 \' \. \' s+ J6 h' X( i
Chapter 2.5 Contextual Sessions
" Y/ ?2 R5 f/ j. v# E  f3 v; }6 Egamahu 发表于 2011-7-14 21:56
: A1 f. t6 f/ r/ V$ d: g4 g# V0 ]2 x

( A- o  Z8 h; j$ B谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
/ t5 P% c  Y% d
2 n" b. N) G: B7 C0 J% @现在还多了个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
( g7 s. g" F* p% X基本参数:
# u) k3 d, {1 L3 O6 |, _5 A& |jta | thread | managed | custom.Class
2 f; K+ Q+ h  y+ w2 x主要是配合
/ S- R+ {3 K' W7 B, P! Z1 n! GSessionFactory.getCurrentSession(); v, |$ G! ~/ ^6 c7 y2 y
来用的.
* ^1 q' ]3 x8 M' M+ m) D3 pThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,* \8 n& B) C& v0 O$ \- w
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
2 s, V$ V: ]0 ^/ O* M2 F( n8 bcontext.BeginRequest += OpenSession;* D4 b2 g4 q4 l$ ]
.Bind(HttpContext.Current, SessionFactory.OpenSession()); i% [1 [1 `' R+ j
: f: E6 t9 k# ?5 Z
//do transaction. O% C4 t& t& U3 e7 F
getCurrentSession().Submit();
# U+ \1 x0 z2 VgetCurrentSession().RollBack();
8 M5 W- m0 L5 s  a6 E6 p! G...
9 C  ^, |2 z! J& T5 ], `% pUnbind(HttpContext.Current, SessionFactory)
% s& c. f! k+ a2 r: j+ b" `5 Z8 P; o) m8 Z& D' B1 p: t
context.EndRequest += CloseSession;
. C9 `5 v  O: L  V* f0 X9 y) i4 w. k6 P# g  B) y
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-29 03:10 , Processed in 0.656464 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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