埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
( j3 \8 [; j2 h4 y& ?' B1 s% p# R
/ `& [$ h  n  j+ ~' K( V谢谢
+ {5 k3 F6 M" W" X0 [& v0 d+ _$ B) a4 n! P& ~9 l2 ?! N
<property name="current_session_context_class">web</property>/ m& z3 y/ }) ^. ^! c1 \
<property name="current_session_context_class">call</property>
0 V& `+ b( X4 O% y<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 编辑
: [$ I8 q9 q% U" N4 j
. T7 s" `) }7 z8 L! o4 kPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
' C3 z; j, M7 M' b' z1 ~( u. B3 U! }7 _. D) b) s! E: u
! g5 @' y1 ]$ j% h
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
6 y4 Q; v* {1 x* z$ \4 G* A# G! C

: x. Y) w2 J, v7 d( K: \' Z2 k( FChapter 2.5 Contextual Sessions
0 \8 ~# R7 Y9 f2 p; {6 ?gamahu 发表于 2011-7-14 21:56
1 g9 ?8 B% t" @

/ m+ X  e$ n0 x# O) ]! J7 m( N谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大./ c- {8 W( g* s' x4 G

- c# q% r* [) Y, u2 }! I8 ?& }" 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
5 F& V) K, }. {# o6 a! l- _基本参数:
4 m  T4 |% B8 a$ }- ~jta | thread | managed | custom.Class  e+ j( m1 ]' E) K, D3 M1 g8 z
主要是配合
& j: _; N6 u, CSessionFactory.getCurrentSession()& b* Z3 w5 C, J" ?/ \
来用的.6 c" S' R! n" r; M
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
7 |& `7 m" {$ C* S2 c; aWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
) w, {% ?1 O' b) G) a; x) bcontext.BeginRequest += OpenSession;
1 C2 ]# l5 `7 c6 I& f.Bind(HttpContext.Current, SessionFactory.OpenSession())
0 I$ a6 K* b+ e4 h: J, m! V+ h# t3 z" D
//do transaction
' d4 {; @) ]" M$ t& H+ @0 l! i" T) ^getCurrentSession().Submit();
5 T; |4 d+ N/ y/ F+ M: `; @getCurrentSession().RollBack();
8 ]8 o* x) E+ t9 b...2 F! ^- Q. f( B9 l6 V7 |+ [/ a# @; g8 _
Unbind(HttpContext.Current, SessionFactory)5 a3 [5 `, ]0 {/ P4 c
; R+ V! T# n  h, o% t
context.EndRequest += CloseSession;) F  c! n1 F) u, N# F0 Q

6 I8 q8 R1 Z3 U$ p  W! B4 y# M 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-11-27 06:20 , Processed in 0.165949 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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