埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?- N, f- D# E0 ?2 y+ V6 W: s9 X" T- a0 ~

7 F0 q) k; J. r3 M  |5 D( i  Z谢谢
2 T) I- w' |1 J: q& |/ ^
& C& l0 ]5 e& D1 l( J+ o<property name="current_session_context_class">web</property>
  }% J4 z" }4 q$ R- ?8 {<property name="current_session_context_class">call</property>
9 j! Y) G9 R: }3 G; I<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 编辑 : O- v1 M* Y) N' _$ t
1 ?; O/ ~. c9 D) S) F
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
+ {2 G" G5 d* Y8 G1 A# P) Z9 |8 }: F( S9 }- }* ?! s  U7 d1 L. N
) R' q* B, Q8 n2 G+ O5 v) Z
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
( }, l7 {$ i* w( ^* u6 y% W3 r
% ^$ I( v+ u9 c) x/ t: k# X3 l7 E- P% O. f
Chapter 2.5 Contextual Sessions
1 [% ~+ S" K0 V  E3 A' Vgamahu 发表于 2011-7-14 21:56
# n: v: p" c) s: L/ Y2 q
5 X" W  z' G2 }
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.' |! b$ x% w1 F  R' e# L
; B  N/ b6 t/ G' u
现在还多了个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 U+ s, F& R# z. J* W基本参数:( h0 w) |& p& _$ f% k, C# k
jta | thread | managed | custom.Class
; M' u7 Z7 H0 C; a0 f/ K+ c主要是配合
* {2 Y) W5 F. W, qSessionFactory.getCurrentSession()5 y8 ]2 t2 Y, ~8 C% Z, y
来用的.0 q( u  {' n9 b
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
/ F7 b( B- J6 ^$ v" r$ M1 s3 y& |Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:8 p5 k2 n7 M& q: ~2 @, V
context.BeginRequest += OpenSession;: m, @+ c5 l* D
.Bind(HttpContext.Current, SessionFactory.OpenSession())9 R9 E. @7 ?3 k9 O. y. l

; I/ O7 @8 E# ~//do transaction
7 u" s- x& N& f; G$ HgetCurrentSession().Submit();
- D7 H) J) P# Z, h! Y2 ugetCurrentSession().RollBack();
6 w4 D9 O: L1 D' B* M2 _4 X$ h...
( K# |1 o6 Z5 @Unbind(HttpContext.Current, SessionFactory)5 H* _( E4 ]. H( S( K% n
2 ]" o6 C, ~  c& Q1 g  J
context.EndRequest += CloseSession;) Z2 ~# K1 [, J5 o

# t, r1 J7 G/ k7 O4 r" Y% g# o 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-21 13:32 , Processed in 0.142814 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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