埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
7 L3 G( `* a/ T! \) g7 h$ e' B9 D4 \$ y3 l
谢谢
+ W8 p1 x" n% k) {1 h+ ?) U) e. g3 s' o( A
<property name="current_session_context_class">web</property>
" j, ?; Q% B8 M' T: K( h; z" N<property name="current_session_context_class">call</property>
4 y2 h7 u# u4 Y3 ^# D8 w' Z, c<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 编辑 : q$ \8 X% E( o& D. P( o' V

- b- }. w( a8 t4 ePlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' s( Q/ t3 f1 Z
: o6 O0 J$ z$ c& y$ Y
, G' @9 j  k8 I9 I* U( c7 y
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
* R$ W6 x9 v4 L$ \" w+ u5 l6 o- y# t' O1 g- Y( G) I
+ m1 ?3 u6 K# E' _  j
Chapter 2.5 Contextual Sessions# V/ y4 X4 \3 `) y2 I
gamahu 发表于 2011-7-14 21:56
% H" A, m$ R' t! D/ q
/ T, [4 G/ [3 r3 ~
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
- d1 e. b3 d# W. z
, g; K- }" j& T现在还多了个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
% G; b$ ~' {! U1 n+ m  Q基本参数:
; R# E  [5 v- y/ f, o8 T# _  Njta | thread | managed | custom.Class
! m  Z/ X9 r+ F, Y5 Y3 F主要是配合1 c5 ?3 |+ F# n" u6 @, ]
SessionFactory.getCurrentSession()1 t, `/ M2 l. u/ V( t
来用的.
- u2 t; N6 _6 P" C- oThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,  p4 u. {  v$ M1 _+ g' J/ c
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
* `/ m# m! G* ~' G! _( X! dcontext.BeginRequest += OpenSession;- f" y6 F9 E& H+ n
.Bind(HttpContext.Current, SessionFactory.OpenSession())
, p. P6 S9 }, ^! j4 S" e% y
% v9 C* s, }: V# C//do transaction7 t/ o6 P- u7 G. v" z& {& q! n
getCurrentSession().Submit();
- C8 \+ U/ G* }+ x1 X6 U3 @getCurrentSession().RollBack();
- O  x% m0 q5 g# A8 [4 `$ n...3 \# c6 D7 h% g/ l) k/ M' o
Unbind(HttpContext.Current, SessionFactory)
% G1 D  q" x( A! r6 c' W; E3 E$ n) S# T
context.EndRequest += CloseSession;
; e8 `- L' I6 B) Y' m/ H( V+ K2 l  E; y0 y. t
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-23 02:21 , Processed in 0.141902 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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