埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?. Q+ o7 N" b5 w3 y: @" n* X8 d

* f4 w. B$ M/ c  t8 ^0 V% F6 T谢谢
8 U1 s% J) ?) U% I6 K& ^4 Y
0 J9 }: d$ `* l$ T6 b% y<property name="current_session_context_class">web</property>
# h# u9 v, t" V. r$ C6 x3 C- j<property name="current_session_context_class">call</property>
% M. Y' O$ N" _4 n* R<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 编辑
. b% v- I- F; O& W
7 p, }1 r4 e0 t! E: o' b. |3 QPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf3 t6 m+ @' G( u& J' t5 `
% q9 P: c' T/ H6 k) k: `
. [# [* I0 t; k6 m2 h$ N  l
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf. \( @! N2 b0 p2 S

1 o6 x. l; ?, g) U8 g1 e+ j
) `0 h+ G( e! p3 i0 l  v/ y. xChapter 2.5 Contextual Sessions5 L" w+ T" Y3 ]% Z$ Q
gamahu 发表于 2011-7-14 21:56

/ y6 y' r% x6 `4 J
  ]  Q( ?$ a" Z% ^7 h6 h谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ g* S3 ^9 Z' L5 k5 @9 g6 d2 c

8 V6 U/ k' ~. o8 s  N, r现在还多了个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. k5 K& k1 r3 X& Z6 a1 R
基本参数:% X- b  i$ u$ @5 F& q6 v5 b$ }
jta | thread | managed | custom.Class
( e: ^$ c# E4 s9 [4 t主要是配合
' Z+ Q3 m# J8 A7 rSessionFactory.getCurrentSession()
; O+ g7 i6 t+ M  ^8 E7 o来用的.
) H+ r' ]8 y4 SThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,$ k7 q: r! c# Z& h1 h% L: c$ Y
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! Q) J3 P2 S" G4 m! ?! @context.BeginRequest += OpenSession;
; [1 j- ^, ~7 o5 h1 I) D.Bind(HttpContext.Current, SessionFactory.OpenSession()). v( ^/ u2 z! ^

1 \! [% o  f2 b; k//do transaction) L3 @# p/ v6 r0 P8 c7 X3 e1 j
getCurrentSession().Submit();1 ?) i1 Q5 ]! G! M  M% q2 i9 g9 _
getCurrentSession().RollBack();
/ a8 H1 n- g1 [' m...
7 B! P: e  X! ]+ o% l( Z, nUnbind(HttpContext.Current, SessionFactory)% H/ t% g4 D, J5 P

% ?2 E1 _  m9 y1 Ncontext.EndRequest += CloseSession;
. I+ Q4 D) z: p2 h: D
- `) O$ ^* y( g6 b7 P 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-20 02:59 , Processed in 0.075512 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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