埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?( ?& G+ O! l  ~4 Z4 G7 I% w4 k" V
) P( U& E: K( _) e2 ]- o
谢谢% c' h2 c$ |" f$ n6 v% t7 K

% y& @. ]3 S7 w8 e+ ^1 a$ \: b<property name="current_session_context_class">web</property>5 |! y7 W( {6 C+ `
<property name="current_session_context_class">call</property># j: D1 _0 }9 O. J  t9 N* I! t; K
<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 编辑 7 B( n2 n8 ], J6 S1 m( W& l* f

8 A, e9 H' V* G# x$ sPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
& Y, W0 o0 l$ P) Y0 c+ A6 `2 E0 D( b9 z

5 d* z) w. L4 h+ J' vChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
  J" U/ J# Z- U- V: w
, x5 X9 n7 ]& l7 }. h8 ?+ _1 K9 Y( W9 ?( p. K* W" ]8 q, q& g$ u" q
Chapter 2.5 Contextual Sessions3 I. i! K& p/ z! E. r: u& [. U" t
gamahu 发表于 2011-7-14 21:56
  f0 H% U2 D# G' r/ D$ @& N. Y

& w" `7 U4 K; u9 @9 h/ }6 ?0 O谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.3 }$ y, J2 v4 e# t8 [8 |; q& R0 k

4 j) v( ]* l' Y0 s! S3 G! l% g3 d( W5 F现在还多了个manage_web,很想知道它和  web/thread_static的差别,也许它能  解决我们现在要解决的问题. 因为 web/thread_static都用过一段时间,   都偶尔有不稳定的  现象出现.
鲜花(2) 鸡蛋(0)
发表于 2011-7-15 09:55 | 显示全部楼层
current_session_context_class 主要是用来配置当前 data transaction session bind to what2 D% h) `1 c$ k7 h" o
基本参数:! D& ~) }3 v/ i  q
jta | thread | managed | custom.Class7 S* J! v" O4 ?$ t' p6 A
主要是配合( Z8 O9 l! t1 ~( q
SessionFactory.getCurrentSession()
: ]- ?- g/ F. @7 c# T, U来用的.2 M( J3 e1 {4 x$ P* @
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,+ T. ]4 R5 l# V6 Z- z, M7 @
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
3 D' A. o$ I* {0 {. f# Lcontext.BeginRequest += OpenSession;
# A4 n' }, h3 L6 t.Bind(HttpContext.Current, SessionFactory.OpenSession())
$ x; m* P# Z* d% D/ y. f
" u1 I' @6 ?: i- Z//do transaction
4 f6 z  K/ O. mgetCurrentSession().Submit();
" k' R* w* V2 n3 K" QgetCurrentSession().RollBack();
% J1 ^- m" _+ m, H+ J..., Z4 H0 T7 q7 F7 R/ B+ v4 k
Unbind(HttpContext.Current, SessionFactory)
! X0 L6 R& v6 w
: b2 m$ S0 e% ]9 ?  x4 q+ u& {context.EndRequest += CloseSession;
. o9 v0 p2 Q- Z+ `: k1 ^3 c. T9 ~# F* G5 @
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-10 05:25 , Processed in 0.156900 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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