埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
1 H: w5 v* z3 G* k8 I& k
0 M# P, K  ]0 E7 J谢谢  O  k% Z9 W* I# Q. P7 ?6 w5 {% ]
# c( Z; o5 o+ c% ]/ M. q
<property name="current_session_context_class">web</property>3 C  W0 O* f7 G4 \4 g9 ?. N4 e5 P( E
<property name="current_session_context_class">call</property>7 l& }" T5 L8 B( 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 编辑 + z* f* O+ ?( y, k( b5 t

: }* {, t0 o# n, b7 U2 EPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf' }/ G6 g0 I+ d# N
3 x& v$ I  h* ^4 Z* C

& U* y8 d$ G5 F7 U4 D& O9 QChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
1 _" I: ~) U1 S* ~: L  \2 l
6 `: |# I1 i6 V9 S+ V; q% _2 ]7 i  b0 j0 t! e# p
Chapter 2.5 Contextual Sessions3 ~6 O( l8 e1 \4 v
gamahu 发表于 2011-7-14 21:56

  a* c0 f8 n  Q3 p1 H, X/ l- ?# T
: m. e3 K; h4 E谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.6 b: e1 j) G4 S

. A8 S# ?' U: U+ E  X现在还多了个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" j1 F1 O% t" O  S& m- W- Z
基本参数:8 q8 \* h6 s( n
jta | thread | managed | custom.Class4 d& K+ G2 R! j
主要是配合5 h4 n6 k+ x( \+ a
SessionFactory.getCurrentSession()
( u: G8 y9 W" v; l7 m来用的.% e4 L$ t+ _3 G/ n" t5 ^5 s
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确," x5 P/ v; ]' T4 s9 b5 L6 }
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
9 @3 ^, O5 Y7 l) k7 c* C9 z1 ~context.BeginRequest += OpenSession;
: T- Z; U% g; k$ T/ v# t.Bind(HttpContext.Current, SessionFactory.OpenSession())
/ w* T$ j" t2 k+ o: z5 T# P; G$ B% ~9 X  C8 ~0 {. X. D$ W
//do transaction' M0 W( q4 W: {5 d; M+ f
getCurrentSession().Submit();9 W6 l$ b; N( M' ^, D- l
getCurrentSession().RollBack();* V1 ~: `& K& b; H- ~! d( g
...
( k% b& E0 s* N" g/ \+ y( ZUnbind(HttpContext.Current, SessionFactory)
3 P# t1 h6 x1 j* `3 m- Y: I6 m6 v  L4 ^7 B! F! t! g( K
context.EndRequest += CloseSession;/ b* J7 w6 o$ f( P& E
8 ^+ c6 B- R% A! A' A) H4 P
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-1-17 11:56 , Processed in 0.094568 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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