埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?* e" [& Z  N' I. m/ |
1 b/ Q; c9 {9 a; \5 ?/ f
谢谢% ]( ]; G# y3 |' H
; d2 A/ g% V9 Y
<property name="current_session_context_class">web</property>* `1 m/ m0 J+ [& @  O
<property name="current_session_context_class">call</property># i" F( f$ E$ W5 X2 p2 ?/ }
<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 编辑
$ m9 n. S) ^& [4 y
6 c: B& c4 ^% DPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
  v; w8 Z  k7 e* ]& e; L3 M" [" Y- H4 ^" T" Z) F1 [1 `5 q

6 j' }. S2 _! h% R. a$ ^8 l# K5 t& y% ^Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
2 l: B! b. V' l5 d
" V3 N" Q+ g7 ], s! T5 \3 D
  \3 N! T. d9 k9 Q; \9 `- KChapter 2.5 Contextual Sessions! S  l" K9 t' {
gamahu 发表于 2011-7-14 21:56
5 M1 Y2 ?* ?* z8 _0 k2 R& x9 A7 y
; b3 Y/ ]9 @6 ^/ T
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.7 X( n/ B3 W8 Q0 L$ i

2 R# |" n  J" E现在还多了个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) _) ~, b1 A' s( f6 W8 b
基本参数:
( m5 [% N$ {6 q  P" `jta | thread | managed | custom.Class2 G) l$ f0 P; J* z- x( t
主要是配合
- S# ^/ @9 q+ _7 Q  USessionFactory.getCurrentSession()
0 `# J6 g( u  F. Q8 O: r( M( d来用的.
" M4 ?: M2 I4 Z& m! UThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ D/ C2 B; B" B8 W; G
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
8 T9 b8 G) o' I) }3 x. G, Vcontext.BeginRequest += OpenSession;1 }1 ~5 b* I  j: X" n! I
.Bind(HttpContext.Current, SessionFactory.OpenSession())
! P  q! _# [( l5 x$ l8 B1 W2 {8 u# H, L- U& }  V: X1 [
//do transaction% H' Y$ _7 Q! f! v
getCurrentSession().Submit();
8 K  V+ h! U# g! n* IgetCurrentSession().RollBack();
: a9 j: I0 F( @; }7 ^4 ]...& q6 V% o% h2 ?: K5 B
Unbind(HttpContext.Current, SessionFactory)% @% b9 i! C: z: x
% }9 _4 T+ p# A
context.EndRequest += CloseSession;
6 n" n6 n, b5 H( F1 V& a' C& v7 X: V: o5 g
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-7-24 01:23 , Processed in 0.188215 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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