埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
. P! ^; c) R2 D% r2 w$ Z0 \& U8 v3 C! ?% P. F: j/ K0 o
谢谢
- q# P) C6 y. f8 k; M
/ n7 w) f; y* h/ @1 d<property name="current_session_context_class">web</property>
" b3 S* A5 u$ I- g2 g4 B<property name="current_session_context_class">call</property>
0 N" }. f7 C  r7 h) z( M2 }0 F<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 编辑 0 s+ M& k+ K1 ^- J0 V
% v9 h4 |* w$ ^$ s+ J1 u9 O
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
: I0 f" I: A- @3 F. Q, a
6 ^9 l# d, I! K* o( z& V7 i: a& l$ \! }# T9 |( S9 f' @
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf4 J4 D0 `9 d. Y- F

) i$ t/ c. z2 y8 G! \. ~/ b6 M. Z
Chapter 2.5 Contextual Sessions) ^1 J- Y. u. p6 ]
gamahu 发表于 2011-7-14 21:56

0 V6 A& Z1 a1 n2 L. B; {# f. j( \0 q- o
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.$ H2 y& u/ x: b
; u/ i" w/ j# U) M; z
现在还多了个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
8 \) V, y1 Q1 u8 p. Q基本参数:
: m; g, @- ]: A1 ~! ?  m+ f/ L1 Mjta | thread | managed | custom.Class
/ c6 B2 v8 }) ?7 {主要是配合
: i# N6 z9 h5 f$ N- V7 M& U7 `SessionFactory.getCurrentSession()+ u' @0 |3 W% u7 v
来用的.
! k( Q1 e% @; w" D3 w( `" qThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,3 k$ p1 w8 Z. P4 u) D$ n- q4 @6 C
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 w0 U' f9 y; C5 Z
context.BeginRequest += OpenSession;
  a; \4 p" {6 g- ~9 F  H.Bind(HttpContext.Current, SessionFactory.OpenSession())
" P4 E3 W) @7 e$ P1 G0 _2 {6 W% b
' k8 z& J0 P# \- i! q# \" ?: t- n//do transaction0 w( p! K' C! ^! g, p& B. U
getCurrentSession().Submit();% s* p& g4 C* M* Y4 ~5 C1 i- s
getCurrentSession().RollBack();( A* `0 ?! V# e( ]" `6 e7 {
...
+ {& ~* G, y3 x7 M5 M# s! uUnbind(HttpContext.Current, SessionFactory)) s, `& d# v) x9 C+ g1 ?0 g8 `
. k2 b6 Y. v1 o% u% k
context.EndRequest += CloseSession;
) _+ Z, ~0 F1 g( b* {! B0 m# H7 C: R% q
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-9-28 03:15 , Processed in 0.174941 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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