埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
老杨团队,追求完美;客户至上,服务到位!
能否说说以下三个设置的异同啊?7 ]# O& A* _$ g9 M% v) M/ v

: k# [7 h! W% r8 f0 \谢谢
3 a( w9 ~" C& B5 V  Q( W" u& f: u4 E! F# k3 e
<property name="current_session_context_class">web</property>4 x6 ?0 W4 O3 y+ s5 b" b
<property name="current_session_context_class">call</property>: F8 m3 _+ h4 h( D- 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 编辑
0 |0 u) \8 H$ X1 M, i* t6 r% |3 g$ a# B
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf; D7 H: u  j* w: x

$ }* Y/ e% }& q. W  v4 n9 G$ W# `7 ]- }
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
老杨团队 追求完美
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf! h: X# f) {( ~! t! [* S! y* |
' K1 E2 q6 a0 R. F. c" o
: G6 G$ P5 M3 |) n; `
Chapter 2.5 Contextual Sessions
) P4 l3 E2 {4 j0 |: _# Wgamahu 发表于 2011-7-14 21:56

5 V& n# {2 B/ y8 v4 U3 g, p6 ]  [; M
谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.' m( z$ j# ]; t# J( X
% f* r0 ]( [: G' {4 |0 s9 p
现在还多了个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
5 x1 _# f* `0 c2 X5 i+ [. A' G- ~基本参数:1 S% z" x2 v4 W: {% n/ v
jta | thread | managed | custom.Class
- q% p5 m* U* n2 f6 E2 b7 t主要是配合$ ~: S; w1 z0 h  U6 U8 T  y" K
SessionFactory.getCurrentSession()
: G0 y, ^1 a# U8 c! k# e, C# [来用的.) e; L% y) o$ g+ B  f2 l# A. H8 q
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,
3 ^8 x1 q; o4 |( r* H: Y7 E* GWeb application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:
1 v  ]* Q7 Q1 G# ?context.BeginRequest += OpenSession;. e. R. D& f5 C9 D
.Bind(HttpContext.Current, SessionFactory.OpenSession())7 y8 ?7 Z3 \/ r' z  I1 ^4 i' C

, s+ e- L9 m$ [+ B$ o//do transaction
9 A) Y# M4 Q( f, t( z' {. QgetCurrentSession().Submit();
3 ]/ _- O# Y1 G2 U: ]9 {getCurrentSession().RollBack();
  p* y, ?( \, [6 d...
; l# ]2 S/ W: j6 W* T( g0 vUnbind(HttpContext.Current, SessionFactory)
8 g5 T4 W2 P7 o$ w( T7 J2 l
6 ~5 J" f/ g. x! z1 k2 Q+ h3 T$ ~7 C0 l" V5 hcontext.EndRequest += CloseSession;
! B4 Z3 w) \" j0 q9 _3 U" H3 D8 K/ e7 ]$ A* d' @4 \
如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2025-8-7 21:08 , Processed in 0.159746 second(s), 13 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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