埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
' o/ Q. s  z$ }7 `# a( _
# [& h& ~! I1 b& k; l3 K谢谢# M: A7 W. X3 R" s

5 h; y7 N- ?' m9 a<property name="current_session_context_class">web</property>
5 d8 q1 \7 Z. \9 }5 a) a0 ]" C0 L: _: ^<property name="current_session_context_class">call</property>
- F2 @5 R0 |' E2 c# ]% @<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 编辑 / h+ O: r& t- N! s+ k. ^

9 \$ B3 o& ?: c! Q. A; Z" ?: }, y% fPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf" d7 K. @/ T! _- P

+ i+ d& \( h& W
$ c8 l$ `: d- u! dChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf" m" |1 o) T+ q+ I
( f3 V2 c' r: ]1 u, V) }0 }

4 d! ^. {" A# n4 vChapter 2.5 Contextual Sessions4 h% I/ J1 V# I% F
gamahu 发表于 2011-7-14 21:56
6 V( w0 d: v- c$ [1 C- w* s4 l) s

. C- Y2 g& I) A9 Y! |谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
+ |& R+ p' K; R& u/ W0 }2 M
, m+ g) |9 O$ v现在还多了个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  t% G& [2 f9 j* g3 L
基本参数:7 X  h1 \& Z& C" @' L: g  \9 D
jta | thread | managed | custom.Class
0 M: |' D  S/ u# }$ I主要是配合- P" S1 \, l# A( ]( Y
SessionFactory.getCurrentSession()
' h- Y: }8 |% d1 y" p7 F来用的.2 K2 B. k, }( u6 h/ g/ q+ Z
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,6 {, g& N7 |& q8 H6 p% p( @
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
; u; |' x! \. O: Z' A; [' ]context.BeginRequest += OpenSession;
- L$ H5 a% z; O+ q3 M- {; r0 u.Bind(HttpContext.Current, SessionFactory.OpenSession())
1 I, V" \+ b% D
" t% t+ X& z; S! z* `2 }4 {//do transaction- [- i, C; \5 e9 r7 l3 u. }+ k& O
getCurrentSession().Submit();! i, ^& G+ i, K+ z7 S/ D
getCurrentSession().RollBack();3 _% y4 x# x/ w% w# B+ M
.... a7 G8 w7 k1 j8 F3 c# j
Unbind(HttpContext.Current, SessionFactory); m& T7 ~/ X' @( q0 x1 Q: Y

% A& G. t- i: H! [* P/ Fcontext.EndRequest += CloseSession;
4 E& u/ X/ g/ I4 K+ h) v" p1 b' L8 Z' y
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-16 06:21 , Processed in 0.172246 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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