埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

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

8 o3 x: n* v( t7 C6 x' ~谢谢; g& {" C* A5 \$ |" \% C0 |( h

6 }) Y' b0 E% y% Z3 S6 C8 L# m<property name="current_session_context_class">web</property>4 M4 g" f: \4 p' t+ \
<property name="current_session_context_class">call</property>! k8 A3 }- r4 s' ~2 x" w3 ^( l
<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 编辑
2 L7 m. t% D7 ]" S' P5 U6 t: k4 q; ]. ?
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
$ u3 H7 |4 N& ]% C6 f  p: u$ G* Q
( H+ F+ L8 O2 Q& Z! [8 I# W
2 i" g9 x6 x; S4 U: hChapter 2.5 Contextual Sessions
理袁律师事务所
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
2 k: \9 B# o! A, ^( b) E, I: ?0 W: W. [7 }1 w

1 y$ P2 s7 J2 U& aChapter 2.5 Contextual Sessions, o. \) D+ k8 x/ e4 J3 \
gamahu 发表于 2011-7-14 21:56
, j; I6 q$ A( O; s( D
5 y5 z, U9 N0 [% b
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
# }- ]9 G9 X8 w2 B9 i
0 g/ \/ z7 ~* J4 W5 |& h% P3 q现在还多了个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
/ b9 I* T1 t: p, B: e基本参数:; v/ y  p' l" Q$ Y0 V% a; j
jta | thread | managed | custom.Class8 j. I5 B* n1 t: l2 J0 `
主要是配合
- u* ~3 a$ D0 h6 P3 e! p2 L, kSessionFactory.getCurrentSession()
3 J+ _4 l2 J4 R  N5 }来用的./ r: k, {, @6 @2 W$ u# S
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,& A4 d' E7 ]6 V/ ~$ _
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
7 V% \% F; j0 t" F- B* Econtext.BeginRequest += OpenSession;
% G, H- f$ F) f.Bind(HttpContext.Current, SessionFactory.OpenSession())6 C: @0 c  n: o* L
# B- Y2 g: a  ^5 ~- s( x* Z7 A
//do transaction( D. h6 U/ Y! L
getCurrentSession().Submit();
, C. x- B- t2 X# T  E2 JgetCurrentSession().RollBack();9 s5 [0 E( E: B7 y8 v% H$ i
...
- P* Y) o' ^& X2 U& }8 UUnbind(HttpContext.Current, SessionFactory)
2 w  D$ M3 T9 w5 K- A7 b- Q/ o- [7 V0 a
context.EndRequest += CloseSession;  O9 |' W$ {0 t7 y( ^, M

7 N1 ?0 L8 Q+ R 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-16 00:14 , Processed in 0.110982 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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