埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?: D! q9 `/ P; F$ O6 t

$ G/ v+ @; n# U% M. m' u  Q谢谢
6 G. F0 J9 o) Y& C
: {) \! t% f( A9 l% ~; [<property name="current_session_context_class">web</property>
0 Q% w/ W: m( {, R4 d) e0 V<property name="current_session_context_class">call</property>) ^$ ?0 ]! M9 w
<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 编辑
( j; k( j4 ~$ e# ?' f" N) Q% c, p4 q, ^
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf8 P+ B( n1 y( Z/ }" T9 t

0 A9 _  q0 J. X+ o! Y' H1 Y- [8 u8 p9 L- T
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 z- f2 i, k6 z3 ^% j2 w
( R0 D, @! U. U, w8 e4 n
1 u' t+ H# A, G' p" _. r' KChapter 2.5 Contextual Sessions7 U7 M- P# r. W6 a
gamahu 发表于 2011-7-14 21:56
( ~6 P( l, f; j9 P! d) Q3 s5 x

1 P2 a$ l+ c0 R) `$ x3 n( G谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
; \9 Q2 y$ f8 b) r8 ^1 q: H- g, ]# Y( V- \2 ]% e2 t
现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what1 q1 m1 i( e& G% \
基本参数:
, T( D8 X5 ?' y1 ?( r; \( gjta | thread | managed | custom.Class
( u6 I& N" I6 [主要是配合5 s6 `. s8 q: P- V
SessionFactory.getCurrentSession()/ A* J% r  d& y
来用的.
. h4 l, k6 x$ t1 J. D) z, WThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
1 Y' @  O+ F) ~$ j* f) ^$ ?Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:/ n* ?  R3 z. c6 o& ]* [
context.BeginRequest += OpenSession;  J  t' N  s2 o
.Bind(HttpContext.Current, SessionFactory.OpenSession())' p6 d+ N- }) Z& V

2 C, a5 v$ P/ N//do transaction
+ B! X7 x9 Q9 @5 A2 j& MgetCurrentSession().Submit();# C& L, w4 `# }! |
getCurrentSession().RollBack();
$ V+ n9 o+ |+ ?. q0 s..." H5 p: W9 _. _% I! [: q1 r
Unbind(HttpContext.Current, SessionFactory)
4 f3 ~! ^1 b9 R- G* m& H" ?8 y% R5 g( j  l; U; C4 k2 v+ v+ h2 u
context.EndRequest += CloseSession;
+ _8 I' V$ b. x. G: i) J. P" O- B) Z- d% j/ u" G% N/ l+ _6 B& ]1 [
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-7 01:56 , Processed in 0.224428 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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