埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

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

4 B0 B: P0 f$ Y4 m谢谢& n6 j: Y9 \' c& A) e/ Q

; R) ~' q1 [- K# y# s9 f* w! c# M3 s<property name="current_session_context_class">web</property>
* D( z4 l. Y" }. S) E7 l, ~<property name="current_session_context_class">call</property>
  Z6 q) N. X. D8 `<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 编辑 0 I3 ]; g9 G/ V9 x2 ]$ i
2 [6 s# r( Z3 N' h  b
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf+ t, i+ g% ?8 P" n4 C; f
- }6 e. u0 w( q" F* I) K
# F$ f+ v1 D9 n( a% C! C# e) C. y
Chapter 2.5 Contextual Sessions
大型搬家
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
7 k) Y5 E( m7 w7 g- ]3 A4 i0 L
1 z4 v5 Y7 c6 T& n! [
  l9 F4 F3 K- K3 w: w8 x6 bChapter 2.5 Contextual Sessions" S7 A6 R8 w6 K( H
gamahu 发表于 2011-7-14 21:56
  [- A8 n1 u( }2 @  U

; P1 Q( |: [7 s% g谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.- B) M* V& X9 q6 M) {* L4 Q

, A& [0 I' d' I现在还多了个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
8 z- t( k/ R" c! [# f- ?8 z* N; T  M基本参数:# V# v$ ]8 T$ C2 K2 _
jta | thread | managed | custom.Class) _& b0 R2 L7 C
主要是配合, N; X7 |0 \: d$ g
SessionFactory.getCurrentSession()0 i' A8 s9 S6 P, e' {+ R
来用的.* d3 v, a$ S) e6 L* [- x
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
1 U# G2 b( ]  E. B" `Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:. q" a; L3 _: \% b  V
context.BeginRequest += OpenSession;+ u  A: z7 k6 H7 x4 I9 S9 U9 ]
.Bind(HttpContext.Current, SessionFactory.OpenSession())
' V2 T3 ~, N4 D% j! m* {5 P
4 z  E1 D4 X- w/ q//do transaction+ T7 o* A+ D. f9 L# y
getCurrentSession().Submit();/ ^6 Q( ~7 x/ a5 j
getCurrentSession().RollBack();. b7 t0 W3 R+ X" i* k# B0 I- A/ H- e
...
0 L& p8 O& |- d. ?" u2 F+ U: j$ R2 KUnbind(HttpContext.Current, SessionFactory)' a1 `1 t- g  _* F
# ?  ^1 q! ~8 Y# j* K/ b( Y
context.EndRequest += CloseSession;
5 S, E7 t# O( B+ L9 H; J, y8 j
) I) M, t+ J! u) V( U( U9 Y. v* [ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-20 03:44 , Processed in 0.100744 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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