埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?/ [( ?% G4 w& J4 ]
1 G: \# D, U; L
谢谢+ f% H) O, ^3 ~/ ^: J4 D
4 p4 b' L( \( d- b! M/ k. D7 {1 i7 F
<property name="current_session_context_class">web</property>" s- z! J: X( g% |2 q3 G6 J
<property name="current_session_context_class">call</property>% y' ~, L$ p: B
<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 编辑
1 y6 ~2 l" f. Q- D3 Y) w4 y! F* H$ L- u5 D6 k$ ~/ \4 F: p
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
8 ~/ i2 C, J7 y: U$ C7 A/ H+ D; }8 l' _8 c
3 R- M$ M$ p; @4 l0 s
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
, V4 P( x. O& j& L6 u% u0 J$ `0 L' f3 E4 I# \0 X

) f( ~: v: }" Z7 J; Z! J  _+ CChapter 2.5 Contextual Sessions$ `4 D/ y8 L. e! W
gamahu 发表于 2011-7-14 21:56

4 Y" E; R  Z7 m* y0 O. c1 C5 r- ~) Z7 o
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.; ^: ^8 y' K. P; G% E" l
. K  {3 M! q8 m
现在还多了个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
4 p' O- H& @" a0 k. u$ w基本参数:. X8 A1 z# j0 X) [) X6 x6 o' P
jta | thread | managed | custom.Class
9 F, J* P3 M4 @+ V8 F& j- W主要是配合6 w+ R, F6 N% L3 T
SessionFactory.getCurrentSession()
  e5 J6 u0 I+ |9 v来用的.
) {9 R# f; G' ]0 W4 k& c& @9 K( }Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 g$ w1 R: S+ g* AWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
' g, {3 B3 G9 zcontext.BeginRequest += OpenSession;) h  g' u5 s) f. `8 T7 }  m8 K+ m
.Bind(HttpContext.Current, SessionFactory.OpenSession())' }. Q( u7 a% b" {  n: r# `

6 b) [7 ~7 Z9 j5 z0 E  g: w//do transaction
( M( y+ n. ~4 ^, u( {/ R- a/ XgetCurrentSession().Submit();
; t. K9 X  X, G5 i7 Y8 u, YgetCurrentSession().RollBack();" L2 a9 ]! x' I: A/ W- M. i4 Y4 J
...! h- l# y& W. P
Unbind(HttpContext.Current, SessionFactory)
# b  O- A9 m1 d( s9 K# v0 ~8 Q
; _6 X( p$ F5 k- p: S2 Vcontext.EndRequest += CloseSession;
6 \9 M  \) f" v  G7 I
9 s; {7 s9 ]1 O% T2 J0 i: g3 _ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-22 01:14 , Processed in 0.188539 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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