埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
7 \& z3 W- }' Z% J; r, y
+ S' Q  r, z+ p$ V( N谢谢- @( r# V# B9 P' U: q
8 D3 N" r; S+ j4 o3 X
<property name="current_session_context_class">web</property>
; t# L$ r* o: f8 x<property name="current_session_context_class">call</property>2 x$ M5 J/ Z$ s
<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 编辑
/ p3 b/ W/ Z8 [0 L% Q5 x7 y# ?7 U
( n" w& A) V0 h& [) a7 L7 wPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
* z( \. O5 W- W+ A0 d6 j7 F8 t9 S: Q: \

1 G! [: h4 h. ?  x; L# X# [4 dChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf( r' ~# l' R# u  n

2 ^6 @& R; h2 V# n9 M* u% b( i6 ]3 C: Q0 V. y. }
Chapter 2.5 Contextual Sessions* s* L( Q4 r- ~0 h! o
gamahu 发表于 2011-7-14 21:56

! A4 U7 A9 a6 C$ J
8 N6 K2 j3 v- v: q' ^谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大." ^) S# |, k1 F7 F% [
$ |1 o+ L; X& _4 [; D* {) |
现在还多了个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- e5 q% f& x' @- K: C
基本参数:
6 A: q- S* `) h' F' ~; R, Qjta | thread | managed | custom.Class
( s7 _( F$ T4 @  k$ p* J主要是配合1 M% L+ @5 F6 ^3 R3 D
SessionFactory.getCurrentSession()& K! ~5 ~! E% |. E( D
来用的.6 v8 W/ |/ X  O7 m
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,% b) t/ Y/ d' \; s0 t9 b3 @
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
! P0 Q9 z! E7 Wcontext.BeginRequest += OpenSession;, O' e) X# l3 v/ t/ L1 a, P
.Bind(HttpContext.Current, SessionFactory.OpenSession()): H  U. @$ {3 F% [" }
$ {5 T' ~+ x- d4 Y
//do transaction
- D* H: m5 U4 w( tgetCurrentSession().Submit();
* ]. V. W3 c0 H9 C! l" l# agetCurrentSession().RollBack();
/ t! c" j" A1 g9 v( e# [' E& I1 G...& N9 N1 x+ ~& @- M4 B- S1 e
Unbind(HttpContext.Current, SessionFactory)- S0 U+ R5 ?8 j( @
; Z* i! n8 I% J7 o  [0 X
context.EndRequest += CloseSession;
) X, P- D; c0 Z0 n* X
+ ]' g' s+ t7 I- ~5 ^4 @ 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-11 16:15 , Processed in 0.096208 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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