埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?
( @4 Z, Q+ g' }9 u) S7 K
" _8 S; o; g3 B+ l: I谢谢
' K$ q7 p9 [# V- U- U3 ^8 }  U; }6 b" m+ @
<property name="current_session_context_class">web</property>
9 l8 z* Y, ^3 C) Y4 P1 b<property name="current_session_context_class">call</property>
  R8 j: ?; W8 o<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 编辑 : t+ `% y! _! h/ |5 N* |' @2 o
# W* a  S( ?( o# ?. y+ X
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf2 Y' o. E  t0 E0 {; L

. X" c' G& w) ?
1 g% f" `7 z6 o; ^( GChapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf. Y' `+ M; e6 ?! l* _' o3 d4 K

' }% r6 q4 K; Z  L* t; c8 R7 x/ Y8 u6 H- z' ~) W9 s, L
Chapter 2.5 Contextual Sessions
7 @9 M  S. H# O" s2 a/ c9 Z  j5 ngamahu 发表于 2011-7-14 21:56
4 `1 w2 V: N: P6 W
* G2 U6 n% h+ t  S3 z/ C5 M! h
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.
2 s5 {! r3 F! i$ y, h  Z7 C! K) p6 }! ^9 X. T9 l5 g
现在还多了个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! ]" r1 D' w. t
基本参数:
% M. C& v; N' gjta | thread | managed | custom.Class: X7 A; |3 {9 [4 J. j$ s
主要是配合
$ C5 k; E, X* a( Z' JSessionFactory.getCurrentSession()6 l, i$ {- L5 b6 W
来用的.
& g! q$ {. c0 p' L7 J4 yThread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
; M9 X6 z2 C  BWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
' f! W8 H! M7 M8 Mcontext.BeginRequest += OpenSession;8 s; S/ f/ f7 M* k  |: K; J
.Bind(HttpContext.Current, SessionFactory.OpenSession())( P) t7 G7 Z3 _% }1 e% v9 \

. [, o! _  I7 v& ?, O3 ~//do transaction
8 k( B% ^* B. Z2 u/ L8 _getCurrentSession().Submit();
3 I. N( i: n- I; N3 ZgetCurrentSession().RollBack();6 U6 H6 A$ K$ C/ j; t
...
. ~0 j0 e! T: o* b2 z% M+ m" E$ t3 VUnbind(HttpContext.Current, SessionFactory)) e6 E, j; i( s9 K6 Y) X

2 |' ]: c6 O* i0 P; Vcontext.EndRequest += CloseSession;
$ m9 o# v+ K* j5 `% [  s7 h
/ y% A+ U) A7 R; E1 z" f3 O8 t, G4 f 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-2-26 00:58 , Processed in 0.142840 second(s), 14 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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