埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?6 s+ A" n$ t: {# L! x0 f" m# x* q$ @: ^

4 o* E: ]5 p! @谢谢4 l3 h* \2 ?: M0 e8 H3 d7 F. X0 K/ F

9 D  A/ g3 o  W( m# T# J8 J<property name="current_session_context_class">web</property>  T$ K0 p! K: x  o+ |0 Z6 e
<property name="current_session_context_class">call</property>
+ r# C, Z  S( S$ w; S4 t<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 编辑
' K  u( i. t5 d. D. j# |* D" ^- U1 R3 ~4 k  M! A
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
. M# M4 n1 U' f* y: L; T9 {
/ X1 g( m6 }' ?6 r' j% W8 s
4 J5 M9 f9 O" k' V4 Q- p  AChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf3 Y( w# i  ~. W( {+ [
! U! p1 o7 u9 N& F. Y
# N7 x# e) A' W. Z0 S* F
Chapter 2.5 Contextual Sessions6 v' ]5 Q% E3 A1 m: l9 Z' u5 C
gamahu 发表于 2011-7-14 21:56

1 A6 j2 D" O+ Q5 y' B6 [$ z# e; Q( e  q$ q% G
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.# @; i- z% ]: }6 n
5 j& b1 l" y5 V/ a
现在还多了个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
5 ~( i: W  I  b  ]/ f& F1 i+ m0 \基本参数:( \, }9 N% ?; {; ?3 \
jta | thread | managed | custom.Class4 P; v: K) F1 Y3 u; k
主要是配合* w, l+ A+ s2 _
SessionFactory.getCurrentSession()7 P& f: z  V9 `1 o. ]8 s8 O: r
来用的.' E0 g1 L, k! ]/ P5 c9 I
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,' g2 n& j9 D8 K8 l0 V) a+ g. t
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:) V! m( U! i% y7 a
context.BeginRequest += OpenSession;: R/ g' G& h; I3 B# n/ w6 I: y
.Bind(HttpContext.Current, SessionFactory.OpenSession())" H5 g1 g5 [3 [6 y2 X

9 F8 G; y/ D0 `# t1 x9 x//do transaction
% ^* T5 g# a, {: t6 U; hgetCurrentSession().Submit();7 \$ k: h0 e- T# |0 y1 L  G
getCurrentSession().RollBack();% g* E+ G& C' @. o9 q  ~, x
...
9 k9 [3 i, Y9 z5 YUnbind(HttpContext.Current, SessionFactory)
2 g1 w1 x& q$ L! e& X) C
# Z& ?. E7 k% n! T: E! Zcontext.EndRequest += CloseSession;7 \" i4 @( R& g% ~) R
) ^; q: O( B' c; |9 W. L
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-21 00:25 , Processed in 0.161764 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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