埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
2 u8 a  x3 M( i- j/ o( G2 U; T6 X- N
谢谢/ u2 c* e* s; r% n- D+ N2 ]* v$ j
; x# q; `4 I, C9 T9 E6 _+ N
<property name="current_session_context_class">web</property>+ g7 B$ l: E  O) B) i) L
<property name="current_session_context_class">call</property>
* {8 L  }4 @) d2 `7 s# P<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 编辑
& G- M% u% u9 T$ ^5 T4 B( e; ^0 d7 u
+ Q0 n, l2 e; {0 d/ f" i$ B5 ~Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
7 l0 K0 C) ^$ ~, u; h. a6 r( V* x6 o: D% P
2 f' b; M& E/ d% G
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf9 h1 o5 i4 x4 ^  |3 ~8 w5 e
) L. W; l* n8 {0 b- ]* m

6 _% d6 R3 L1 ~# M# XChapter 2.5 Contextual Sessions4 E: Z8 {4 U9 f5 ]9 y1 X( ?; c
gamahu 发表于 2011-7-14 21:56
* I. x1 p) u) f, i
, J% q& f; P# @6 A2 P/ s; s
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
4 s# K9 m" D- \7 p
) }$ o) q. y1 w现在还多了个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
! r, I( g* s/ M/ [# v" E基本参数:
: M5 o$ b* U+ kjta | thread | managed | custom.Class
2 K% b' ~- |# c6 j' w. `; D( E* L主要是配合
: s1 P4 b' r$ aSessionFactory.getCurrentSession()
8 o& ?% e6 ]0 L1 j" N来用的./ v8 f0 L% q" P8 g" w
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,& v9 V6 r: P% S3 t! O- S8 `
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
- [1 v; ^% x! i  a! Hcontext.BeginRequest += OpenSession;
( _: U& E7 [# Q1 _- O4 C" s' m3 W- V.Bind(HttpContext.Current, SessionFactory.OpenSession())1 B" Z' m4 o- M; b: m) M  ?
& u3 Y9 g# R1 C' |# w' s  D* ^
//do transaction
1 E9 Z( b( \% Q+ m& j; S$ Z8 JgetCurrentSession().Submit();  L' i1 P0 D% l) C# ~+ @
getCurrentSession().RollBack();8 V" R5 R2 e! x1 G0 f5 \& `
...
( o* h2 Q* H/ X2 S7 L% C% U8 pUnbind(HttpContext.Current, SessionFactory)
% t& M: X7 L: H# Z$ b; w% o: `8 r- T
context.EndRequest += CloseSession;
7 M- q8 P# Q- X! A; K9 t2 `( r0 Y7 ?  f# Q1 M; ]: @- @2 j
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-12-7 08:45 , Processed in 0.138224 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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