埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
4 ^: P8 B5 s, r2 Z4 G7 q9 n! \- L& R2 o. z# |; G* K4 A/ [' K
谢谢
4 u9 ?7 p. X9 f; d6 S: V% S, |( V' U8 {' P
<property name="current_session_context_class">web</property>
7 U1 n+ v$ Y- T  T  v4 Z<property name="current_session_context_class">call</property>) K/ z8 M" r6 s6 U
<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 编辑 0 Q$ f, s1 q) V7 H5 ?
0 W3 n( c' s0 {8 S5 J
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
( w$ Y& c6 }, h/ [: |
# Q6 G/ `+ q: `$ r  `: D
* D9 h9 G6 B. I+ i: W; fChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf+ A% d$ w( M. j  |  H4 m  v- O) ^
( h) G% {5 V, B9 n8 X
, P, O3 n  ~/ E) }$ g; p; `+ S
Chapter 2.5 Contextual Sessions/ w6 B- J4 @' i8 o, J* v
gamahu 发表于 2011-7-14 21:56
) d4 ~  N$ M: p1 Z$ a2 L
# t  _! B; t+ j& R/ n
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.. Y+ n: b$ Q1 n2 ?  x& b7 K( j& E) |

8 J/ R+ O, A% t+ `$ z* s现在还多了个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
2 k% J* K# T, q, v1 d, @+ a; t( B基本参数:
( v, T& D' ?( D1 \2 hjta | thread | managed | custom.Class$ H3 O: C/ q- b
主要是配合  }3 x7 \) ~. d; b3 ^
SessionFactory.getCurrentSession()# n' S8 E/ R' X9 a+ Q( v' t
来用的.4 {1 S$ t- O! I& V) g2 s
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
, s7 t  t: z, V/ U5 x3 N) Q9 dWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
& c# y+ J2 i/ ycontext.BeginRequest += OpenSession;
. ]  y& U- e" [.Bind(HttpContext.Current, SessionFactory.OpenSession())  l- G, I2 p' v7 x7 n1 s
+ Y$ @2 u" s8 ?) i6 r
//do transaction
' R3 h' i2 N- ]5 C' {getCurrentSession().Submit();
" S( A. r5 O" k: }/ I  W0 jgetCurrentSession().RollBack();
. Z2 C$ o* c, s9 q0 {# G...0 V; H2 B, G8 u9 p# X1 P4 Q2 P
Unbind(HttpContext.Current, SessionFactory)
6 U# m0 T3 `1 [
  Z+ }  ?5 v$ c) Tcontext.EndRequest += CloseSession;
0 r0 y4 d8 `7 i7 a4 l0 W; M
% C: V5 b& U3 j 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-3-9 00:26 , Processed in 0.174670 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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