埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
能否说说以下三个设置的异同啊?
7 S% W' Q$ M& Z. o4 w; T4 |+ G  a+ H. t1 d4 I! Z0 S* n
谢谢: }8 Q: ]' v, d

6 s" |6 G) I5 Y; A$ x+ p4 v<property name="current_session_context_class">web</property>
/ t8 ]; ]1 W, u5 f- C<property name="current_session_context_class">call</property>
6 o/ A: |& o8 w- h<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 编辑
5 G2 F* U0 w7 w  T9 D* R
" H* L. w! H, H) P3 Z) g- T4 CPlease refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
. R, |. p/ {! a6 Y- b$ F% _1 X+ Y) g- u5 A. F! n! ^  j
+ e: C$ ~6 o& X, _
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf
- r- M6 `2 H4 s6 r" \# r$ e2 O' G) H/ ?0 u5 T- |0 F0 U, g. \
  H0 N" ^5 M! A: F3 l  x3 ]7 e
Chapter 2.5 Contextual Sessions
8 ^/ ]* e2 E; ?8 `! Zgamahu 发表于 2011-7-14 21:56
1 l" r: ^3 L9 d) {, d2 J  Y- L

4 S4 B1 b5 q& G- {; ]谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.* w0 T) ]+ `* h5 d" p" r

4 d, i# s9 [( X3 R7 ]现在还多了个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
# e2 O3 d( @: y: U$ t) ^9 C# m, ]基本参数:' D, L- c# H; A! E( P
jta | thread | managed | custom.Class% \  z& b+ ?( K, B& e5 Z
主要是配合
; `# v0 E* ~, G3 pSessionFactory.getCurrentSession()0 b# k% A* o$ m& w4 r2 W3 K$ j# p7 r
来用的.; [8 {! M3 X4 L; m, {# ^
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,6 w2 u0 k' _# O
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:/ t; v) h4 a7 E
context.BeginRequest += OpenSession;
- {0 K( X8 e0 g% E4 _3 O2 y. a.Bind(HttpContext.Current, SessionFactory.OpenSession())
* ^( p5 Y. K0 R0 L% Z2 B9 x9 f% q$ S3 e$ c
//do transaction- R2 }' O6 Z8 k/ u4 c0 |5 |. C
getCurrentSession().Submit();: t9 x9 }& ?5 C9 c, R: ^
getCurrentSession().RollBack();
- I& F9 d3 L! z2 y" q3 k...
+ E- G" }2 w  g% B! MUnbind(HttpContext.Current, SessionFactory)
+ D1 C5 h! y  d7 w/ Y8 _
" R% y# F" f6 V! |  {, mcontext.EndRequest += CloseSession;: \# a9 Q0 S& s$ t

0 r5 Z' P- }3 q6 r 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-11-29 08:37 , Processed in 0.281260 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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