埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
能否说说以下三个设置的异同啊?) o" C1 t4 ]% a8 g# d; B* Z

! |+ S5 T# i  @8 x* m谢谢
' ]; i! N9 N: m! U
* z  W# ?7 T* C- \( W<property name="current_session_context_class">web</property>
* T; Q% A$ |5 j<property name="current_session_context_class">call</property>
4 u/ p4 V  M2 |/ A  d# 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 编辑 / Z8 B0 U/ a+ H8 A/ }

3 ?% c6 S" M% \3 |* P3 ZPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
. s7 ?! Z# T: Z; _9 h5 Z8 q7 m( u  z+ u' u7 K

/ u: J! c3 `. C$ [7 iChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' ^, N8 g' s+ M% t4 T, Z

% W2 o/ C4 ?) ?' k
8 h2 R3 K+ D+ nChapter 2.5 Contextual Sessions' Y$ |% D/ b! L: K- V9 U. l0 U5 ?. `( E- l3 m
gamahu 发表于 2011-7-14 21:56

6 v7 N# ], n& b8 d9 ?; R' v( h. u4 z' {* @" u
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.+ f6 N, w# X$ Q& L

% K9 I3 T- e2 ?/ o现在还多了个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
% S0 C3 j; P7 p9 ]( b5 _" @4 h基本参数:
; `- U: ?9 x; _3 f- l( z( |4 _jta | thread | managed | custom.Class  Q1 r$ R$ y6 F! O* d7 |: L/ \* C9 ~
主要是配合9 O) y, G$ ]# H3 x! v" R+ `* K
SessionFactory.getCurrentSession()
) _5 |7 F; z/ x来用的.
7 b' q: Y; K, q; |5 DThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
. Q9 u3 l3 d. ?2 DWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
( z5 M( X7 X: `, y. c5 scontext.BeginRequest += OpenSession;
; g( \: \, Y# U! l- Z.Bind(HttpContext.Current, SessionFactory.OpenSession())
# b5 `& t( ~* _! o$ Y$ S  d  c% K
//do transaction" J5 b$ ~7 [5 e4 a" [4 P# l
getCurrentSession().Submit();  t! V8 s) k, t+ h
getCurrentSession().RollBack();
4 D( b9 Q: D+ E' L...
+ b( E8 n- T, f+ H4 w! |* YUnbind(HttpContext.Current, SessionFactory)
0 s( ]: K* C* n7 z
/ ?4 B9 y- u; `context.EndRequest += CloseSession;1 T0 B- N, z7 |- x( _  Z/ G6 m
7 L6 T2 Q+ c# F3 q4 Y  f3 D6 ^
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
大型搬家
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-11-1 08:06 , Processed in 0.136155 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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