埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
7 A: P" h/ f4 W: {
- e0 u- V! y( p5 B谢谢
9 S0 ^+ V2 Z# u+ e/ m) Y
! H% q2 B1 U( b. S" g! R<property name="current_session_context_class">web</property>& ], k  i$ I4 x
<property name="current_session_context_class">call</property>- E" E) t3 e. |! D* x+ E
<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 F7 T) z& Z) c& Q( {, p9 g8 F1 \' z% n5 s) R! y3 o
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
/ h0 G+ \& }! W* R5 J/ T2 A$ f% p% b1 C( x4 C
1 {% @. v6 s* _( e1 Q8 `4 \0 }
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf9 F! i. f/ C: h" p5 }; n6 @1 N8 A: \
3 l& N& E) ]+ M& Y7 r8 w& S0 v+ S1 P

- U; J) |4 ~3 m0 t5 W3 G! ~- G# ZChapter 2.5 Contextual Sessions. c/ l; t: ?: @* l
gamahu 发表于 2011-7-14 21:56
& G+ ~3 k' Y- C1 Y' Q$ {% j

4 R4 {1 \* J; m: e. _$ M6 Y谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.4 G! l4 P  H3 k/ k& w
. s( L4 g0 _6 u" J3 O4 Y- c1 a4 b, N
现在还多了个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 G* x- |& `$ w基本参数:
7 o4 t8 y# [5 L- t8 s! yjta | thread | managed | custom.Class: V' V# R& R6 N' N/ K. C% Y' Z
主要是配合' c5 q: s' Q" Y  E) z( q/ M3 U+ g
SessionFactory.getCurrentSession()
! |7 C* k( B+ h: b7 {0 P来用的.
: o5 R& f1 ]$ K. p, T' n7 i0 {Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
8 h1 [' M6 y0 P  K% g/ ^) c) pWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
. u: p& p+ Y0 c) Ncontext.BeginRequest += OpenSession;7 ^; _; C1 M. @' J
.Bind(HttpContext.Current, SessionFactory.OpenSession()): N! D4 q4 ?5 c9 q5 e
6 V  T4 [$ Q. m/ w. A1 Z8 A
//do transaction; a" f5 B3 P7 a% Q5 y
getCurrentSession().Submit();1 F  @1 x; [" G+ G! Z9 _- C
getCurrentSession().RollBack();
5 `9 |. `) V, I- k+ V+ L5 z/ @...
% l4 `3 x$ r6 S! KUnbind(HttpContext.Current, SessionFactory)
6 ^2 w" a! H. v; X9 @0 L. L9 `1 |3 i' \+ Z
context.EndRequest += CloseSession;
; \8 m% b3 R5 y$ f9 W5 a: O1 X
, z( I; K/ e/ P% | 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-10-8 05:21 , Processed in 0.150796 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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