埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?, u) d2 V7 S( [+ H" S  E! d2 u% y

# }7 w/ g+ k* f# ]5 k4 v3 R* K& c谢谢% D( ^9 J0 J, U

/ ~0 i6 E( u7 r2 k  T9 f! A<property name="current_session_context_class">web</property>1 e. B! t3 m5 a' i7 {
<property name="current_session_context_class">call</property>5 ?) B6 I0 N0 c6 S" X9 O9 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 编辑 8 Z* K' j4 L% P; V/ i: [- O

/ {0 M# t. A: c4 u  UPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf3 k" g6 v. P- o; L- M3 i2 X

  z9 ]% D0 `$ b( ]( w3 L* H$ K
0 Y/ k, }: X) I3 L  b5 D; G& ^! `Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' t% B6 k7 }9 \
8 Z7 R1 E( n( M3 c9 X5 W: Q. @
- C1 Q! E1 D& Z- H) Q/ P
Chapter 2.5 Contextual Sessions2 n9 o: X6 M6 G' E
gamahu 发表于 2011-7-14 21:56
5 v$ k: j+ U2 O) Z

; B) _( h  }# K6 S9 e2 Y( e1 k* u谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.$ K! x* Q* v0 N' K# K

8 E  J/ a% f( [: i* x现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what6 _0 t" e" j& @1 h6 W6 V. |9 {' k6 Y
基本参数:7 y; I+ z3 v. ^7 g& K4 R
jta | thread | managed | custom.Class
1 l! ]; L) m# O# P4 w3 C7 x1 N主要是配合
, C/ r0 R' Q# D1 D% u; Q1 hSessionFactory.getCurrentSession()
! S7 d5 B8 \: v. K来用的.$ t2 M$ U0 n6 d, f9 N; f
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ `5 ^" {, g: k# J* e
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! M% Q' }, X- G3 S6 n; Rcontext.BeginRequest += OpenSession;
, M4 h# H+ _& c, F.Bind(HttpContext.Current, SessionFactory.OpenSession())
4 B, e& r* l2 S2 u8 o6 n: x; u
5 q, q5 _1 ^' A3 r2 t9 `* V//do transaction
8 [# t. ~3 w0 D) O$ B8 PgetCurrentSession().Submit();6 o2 s8 b+ M  Y# X+ |
getCurrentSession().RollBack();/ C$ L; i9 r, P8 M. h
...) P% g/ g1 w" M/ P1 h' y. r, g
Unbind(HttpContext.Current, SessionFactory)
3 E: P1 T% _" m8 b6 C: {" j7 Q  ?* q/ r; q" T4 ^
context.EndRequest += CloseSession;! p6 X* V- g' \! C2 j6 T

4 ]  K  z0 V- B# ?+ c" A$ h! _ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-6 18:14 , Processed in 0.078286 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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