埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?, ?( r0 F( I% J: M/ o
* n- T9 B8 {1 }+ _1 ^, P2 C
谢谢1 V) [8 F* V& H4 ~/ q1 N9 p- b
5 R9 i" n* o; _$ @2 n8 m6 Z5 v
<property name="current_session_context_class">web</property>
! q' I8 }+ \0 }; b( z9 X- c) {<property name="current_session_context_class">call</property>. S7 w3 n+ H* e3 X  x
<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 编辑
& |7 R' p5 }+ R2 k5 |
% u, ?5 O0 V( f& bPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
/ S2 U8 P  j% u! {5 ?) C6 l$ m; S! @9 [

  S$ y. D) [4 W4 v5 r2 qChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' {. a, J; T$ h/ }% C3 j
$ w3 w* |, b- V' Y8 [  b

) z0 [) g2 n5 |# r7 M# R: EChapter 2.5 Contextual Sessions
* D# j3 E' b7 k2 [1 u$ {+ l. c/ I+ U! o+ cgamahu 发表于 2011-7-14 21:56
6 o* d# v7 {7 e0 a# B

1 S: R  s' K; |. \; N; J谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
: r  u4 A5 p. {* S4 D, n$ z. u6 B5 j* G2 D$ s4 u" z5 [+ p
现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what9 u- `1 v9 y! K+ L- Y
基本参数:
1 y$ B- ]2 }: I, mjta | thread | managed | custom.Class2 Y' `( t5 X$ ^7 |9 q2 w
主要是配合: j" n: ]/ n2 f* X2 B+ c3 @
SessionFactory.getCurrentSession()$ P1 U1 B. L! ?* f8 x7 w2 e0 d4 P
来用的.
$ c9 ]1 N$ v0 v8 j/ _: @Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
4 O4 t4 m" u3 H' X, AWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
' K& i! y$ @5 E6 ]# `context.BeginRequest += OpenSession;4 S) B; Q5 {2 A6 e; M
.Bind(HttpContext.Current, SessionFactory.OpenSession())$ O" F% H# z  v; T

# j5 _" s3 g5 k: a' K//do transaction3 M" F6 E6 n: ]0 N9 D
getCurrentSession().Submit();
4 Z# M$ ^! L+ [getCurrentSession().RollBack();* X2 a8 j* J. V
...% M8 \8 ], i' l( a6 M% e
Unbind(HttpContext.Current, SessionFactory)$ s* V4 B# H1 o/ W( A# ~

$ n6 I/ w7 n/ w* C) x1 {; acontext.EndRequest += CloseSession;) E$ \5 B1 w" R  g; S3 Y9 q

2 H1 l$ k4 U% c  Z5 I+ A0 @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-30 08:34 , Processed in 0.219850 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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