埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
8 g9 C$ G8 N7 D$ b, D8 s# l5 f" n  j/ O7 U6 ?
谢谢5 Q' f1 V% G+ a% z

; \2 f4 p, D9 N$ Y4 K8 l! Y<property name="current_session_context_class">web</property>3 _6 r5 }# o: r$ [
<property name="current_session_context_class">call</property>) }0 s7 \" a; X' r* B+ D
<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) Q; f8 T) F: l9 |

1 r. m+ \2 a! y! GPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
0 o9 g, g# g1 Z- B9 X$ u: z& a
/ ^  D5 w* x* C( d" q8 {; Q  H5 [
# h% L& k' [& `8 H6 e& v# m0 mChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf* h+ O0 M: h2 {
) `3 ]$ A7 L' u" T

# \( k$ S, ~# f2 fChapter 2.5 Contextual Sessions6 y6 ?( \  T; m# F5 p
gamahu 发表于 2011-7-14 21:56
6 [1 u- U0 E: x0 f
: @/ {# \4 N* d* M: c7 K. s5 k8 X0 e
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
/ t5 e1 t# |! o$ @0 x, g0 d* _8 s3 V  \" O! p
现在还多了个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, p. J3 b7 G. b& h; k# q
基本参数:3 T  T  E0 Z$ `6 h+ u2 ?6 P
jta | thread | managed | custom.Class
3 R7 _$ v+ F5 I/ V% r) \% L主要是配合2 ^& t: F+ \) e* C/ j1 H
SessionFactory.getCurrentSession()0 N. C, n$ G. n6 z* Q0 c: H: z% P2 g( z) F
来用的.
' F1 R* p. q% KThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 P/ k; ^. J2 G$ M3 R  R) sWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:& V- ~! C  s$ s) m
context.BeginRequest += OpenSession;
1 L" l( b$ d: `, Q1 w. B.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 m9 y" a; E( y. x. E
5 M# S% q! O0 T2 D% E! q//do transaction
5 L6 z8 U. o% x0 e* VgetCurrentSession().Submit();
5 Z$ v- S: j: b: g3 IgetCurrentSession().RollBack();
' d- Y( \+ B( u) N2 c...0 j# N2 P' ^7 @, x4 p' m& K
Unbind(HttpContext.Current, SessionFactory)% A7 [4 m: t- k

- {) c: L# q  k! W% Ycontext.EndRequest += CloseSession;
0 v* L% _: E! Z. B
7 _1 @- b; l* i$ p# d3 v 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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