埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?7 R. D: w% p% B7 o, h5 M

7 t9 M; G$ t0 S/ z. a  M: q谢谢6 s5 Y2 p5 @2 w5 C- K7 p+ b1 e
' G+ [; [- D9 p5 Q7 r4 b- o- R- A! ^0 Z
<property name="current_session_context_class">web</property>
  }# L* T# l/ D& K. Y<property name="current_session_context_class">call</property>. V7 X+ I5 M' S& L+ y
<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 编辑
$ X  h6 ~6 {* P  N* [6 G0 g) A# ^/ O# }( x' ^( T
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf: X) H% P  M7 f2 N/ ?# @+ g

, z. [9 B& ^% U. q7 U' t3 j
; ~: h8 Y' p" |9 t8 \, N: g, x" kChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
- ^) L- P) `& _+ t, P( K7 J  P" y6 N: q0 y1 d

! p% C3 E9 ^* E; w2 K, KChapter 2.5 Contextual Sessions
9 R; y0 P8 Z/ X2 p4 K; sgamahu 发表于 2011-7-14 21:56
  \; W, P  o$ y* R# p' X

8 @. q6 {9 D/ N+ ]9 O# {% n谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.- u+ D% e# S: f
7 U7 a2 Z) k7 i8 n2 ~* z4 H1 y
现在还多了个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
9 A' C/ m3 A# \; F+ [% r, a* L基本参数:
+ F9 Y2 G5 T& h+ Vjta | thread | managed | custom.Class9 x7 d! B# V& o" ?, ^/ e
主要是配合& `# |" z* q7 m5 }5 T( ?! _) H' D
SessionFactory.getCurrentSession()
/ ?8 D$ T+ H- P+ S, p来用的.
  ^. ~1 t% K) @9 eThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,8 `7 F1 u4 l  B0 H
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:0 I& C4 n2 I: M
context.BeginRequest += OpenSession;
! Q2 D( L# x2 {0 O.Bind(HttpContext.Current, SessionFactory.OpenSession())
4 j3 L0 N- t' C6 M; K" h9 D
- B# D2 A% l3 @2 g5 d//do transaction" ]+ C3 d: D- F2 n2 P7 C
getCurrentSession().Submit();
4 X! Z( v9 [$ q/ v2 EgetCurrentSession().RollBack();, E/ W6 ~- Y6 c: g
...
$ ^9 }+ i- ^3 [6 ^Unbind(HttpContext.Current, SessionFactory)
4 Y$ T/ N+ \: ~: B
- a' E) r" n& v5 Y) n& h6 c* jcontext.EndRequest += CloseSession;; F% L: e$ O6 y5 s/ q/ _" c) Y

7 P8 A0 w! L5 ^: h0 o( U5 S3 e! i 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-4-13 23:32 , Processed in 0.063388 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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