埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
9 f9 X# v! P% n$ i4 x0 @9 h* {6 ^5 R/ Z
谢谢
  n9 U' |9 ]: w5 C0 t  B7 S! D( U* Z; D' n$ Z% s5 f  d
<property name="current_session_context_class">web</property>3 {) C+ J& _$ ~9 U& ~4 h% L- k! A
<property name="current_session_context_class">call</property># ~& c- P; A  G; u* B  l
<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 编辑 8 h$ o7 Y! r! o. f4 E+ s5 d
" A6 y4 I, w% N
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
; [  \) |; C% ], l- s9 F! C$ c1 a+ F) W. N. _
9 \+ w- q0 ]& z7 u
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
: W- ]& [" m0 M8 q3 H3 v" j. r( M8 O# H) P& c4 ?

7 ^4 k$ p1 W% O8 MChapter 2.5 Contextual Sessions- x# _( r. h7 S+ m( {) p, y+ w0 U
gamahu 发表于 2011-7-14 21:56

  ^, j# N# m1 l& b$ {) l' B4 |9 n9 t
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.* N8 F) E* Q6 ~

7 f; ?: E4 X2 _* s2 v% s  s3 _# l现在还多了个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
/ K" }. c8 g6 z! u基本参数:
/ c4 `* E8 B; n$ m- l- vjta | thread | managed | custom.Class3 Z& M/ h9 o0 A6 S
主要是配合! @# I( n. ^8 ?8 e
SessionFactory.getCurrentSession()
& ]7 Y, ]3 P( A, Q来用的.5 K/ w) D8 F1 Q7 i5 b1 K
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% D$ t! h& w5 j9 \" e* @9 o5 |
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 @" I/ ?: |0 I/ Gcontext.BeginRequest += OpenSession;3 y/ }* |& d% Z# X
.Bind(HttpContext.Current, SessionFactory.OpenSession())# b) W0 b4 D7 B. `; r& }' |/ F

; F6 T+ ?6 @& I5 o% }8 ]//do transaction- i) N( K. [3 v: p; F9 G
getCurrentSession().Submit();2 E: z; E. m! _5 \# g; n
getCurrentSession().RollBack();8 `- H1 A; |$ q/ r: {4 c- K7 x7 p
...1 {/ g$ t8 Y# b* e2 E
Unbind(HttpContext.Current, SessionFactory)
9 e! E: p% J. b( _# _3 M5 w! `0 l: i
context.EndRequest += CloseSession;3 N) j, w+ Z) S' O% i4 Z
/ B+ Y) ]1 @9 {9 G
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
大型搬家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-28 18:20 , Processed in 0.217931 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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