埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
& j: E( \0 S: s$ @: ~9 x5 B# z! ~! \
! V/ y  t# p% x4 G5 {8 H谢谢
* H) a3 H% s1 [3 q+ }/ N8 ~' Z6 Q% O/ d
<property name="current_session_context_class">web</property>8 z1 p; @0 p: ~$ _! m8 R4 R& V2 {5 x
<property name="current_session_context_class">call</property>6 M- Z1 S9 `- o5 Q) g3 x7 Q; r
<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 编辑
9 h' d# ?& y- m  C& c/ v# r
+ I# H" i0 S) e( VPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf9 G) |8 ^2 ?$ J8 k4 h( u
; |' Z1 E- B: m* d8 Q/ K

4 x+ i) m# W4 GChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
0 X7 [4 D- k2 l+ A" u
4 q3 D- p5 @1 ~) r- g4 Y' q/ Y4 N) _& n7 W. t; R1 @
Chapter 2.5 Contextual Sessions
1 i6 |, T) C( vgamahu 发表于 2011-7-14 21:56

0 z* C- q8 G8 A4 w4 M; r# h2 b+ D! t. O0 v+ K1 S6 c4 M* v
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ [" w+ u; y# |8 ?% D: G2 `

& k6 P/ [) }# ?( D* @& I/ i现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what4 R% k) i; e: c! S
基本参数:
2 O0 J; R& V: |1 pjta | thread | managed | custom.Class
& Q: m, `( T: e4 ]主要是配合
; ~5 d. `4 c! l& g4 p- L/ KSessionFactory.getCurrentSession()
  B) D% G# c' P7 n  M6 |. |% v' W来用的.
; j' z8 F* z9 |Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
: S- L1 s, J+ A  mWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
" C0 Z3 V1 h+ ~7 s. r4 Scontext.BeginRequest += OpenSession;
8 j; |. C, P8 B- g( ~' ?.Bind(HttpContext.Current, SessionFactory.OpenSession())$ Q+ x) \5 ]. n

' `- {/ u$ K+ t) u' ]' ^//do transaction. n* Q$ j1 y( e( G  a7 [( G$ |
getCurrentSession().Submit();
) m/ u. k1 e5 B; |1 }+ b  x% JgetCurrentSession().RollBack();! V+ K# F& w/ ]9 l% K0 g
...
( m. ^! I# ?0 J+ `  g' N3 ?$ B9 wUnbind(HttpContext.Current, SessionFactory)
! Z8 q6 t1 z9 I( R/ T+ q  N
# |9 q6 R5 f3 F9 [context.EndRequest += CloseSession;
) G8 o7 t) _5 S6 c) E5 U' L' L/ @" R( T5 s2 ~7 O
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-29 13:30 , Processed in 0.133376 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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