埃德蒙顿华人社区-Edmonton China

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

寻找NHibernate高手

[复制链接]
鲜花(123) 鸡蛋(0)
发表于 2011-7-14 16:47 | 显示全部楼层 |阅读模式
能否说说以下三个设置的异同啊?9 Q# w. u( z( _$ t, S' _; G7 [
% C" {, Y% x$ k1 d4 M
谢谢
- F+ ~# R* _/ M2 ~/ T! F4 j" W  g7 a  y
<property name="current_session_context_class">web</property>
0 S: k% e" d! e+ E1 G, o1 A3 q& a# o<property name="current_session_context_class">call</property>. f  G' ]; Z0 a0 E2 v) v+ 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 编辑 % `$ ?7 o& K% D7 K1 y- X
  Q- P: N( a  _5 Z: Y' x
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf# x5 R( e) s+ h4 ~
: s1 L( F* N  ^! L4 e6 L
! [0 Q1 J$ U" K1 C: a1 E
Chapter 2.5 Contextual Sessions
鲜花(123) 鸡蛋(0)
 楼主| 发表于 2011-7-14 22:31 | 显示全部楼层
Please refer to http://docs.jboss.org/hibernate/ ... rnate_reference.pdf: U. x1 O1 ^$ d( L5 x7 l: e, F

. N1 T- @+ g( V! h4 F  I! D" i6 A' M$ H
Chapter 2.5 Contextual Sessions
( d. g; R% U9 M% P8 Y/ H! j% \' hgamahu 发表于 2011-7-14 21:56

* O) ^" e# d6 q0 I* W
! j# D2 E  N. M/ q. |/ {谢谢啊,看了,但还是很模糊. 其实我已经看过不少关于这个问题的文章或书里的章节, 还是没有得出明确的答案, 他们之间的 界定和 差异不是太大.$ a. Z, M. f) d% h! r

3 n/ s# S8 K4 _' Z: Q0 a( 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. C, s8 ~3 {9 y+ H; z* x
基本参数:
7 x  z% q% d# E5 Ojta | thread | managed | custom.Class
. m7 b$ \/ b& i/ ~9 ~主要是配合1 W" m. c3 w; b) p3 V! b/ h
SessionFactory.getCurrentSession()& s7 Z4 P& X* o/ |; ~7 B* ]
来用的.' x0 a7 M$ f; ]; c1 F- \5 a4 v/ W+ E
Thread 指自动绑定到当前进程,managed 是在有些managed environment 如果使用 container-managed transactions (CMT) , 需要自己bind 和 unbind,这样 getCurrentSession() 才可能返回正确,4 y4 `- O1 f8 b/ ]7 A
Web application 状况下,每一个HttpRequest 都是独立thread, 所以可以在BeginRequest的时候bind, 在EndRequest 的时候Unbind, 这样就是可以使用getCurrentSession(), 例如:9 v9 ?4 s. e6 O) f; ]8 D
context.BeginRequest += OpenSession;9 z* t3 @8 G( H. Y0 P5 ?2 p
.Bind(HttpContext.Current, SessionFactory.OpenSession())/ Y" Q: ]; @4 G' S

0 }( ]$ ^8 ]4 p6 c+ ]8 n//do transaction' @1 V# F/ A4 p. o
getCurrentSession().Submit();
  `& X8 ^; S. y6 l; E* e5 CgetCurrentSession().RollBack();
9 K" s/ V3 f/ e7 P" b. r3 E! x...
( m2 K- t6 @" i4 [6 B9 qUnbind(HttpContext.Current, SessionFactory)
* f# a( J3 |$ s/ G' ~
/ @8 c/ e7 o9 Z  Y# `/ pcontext.EndRequest += CloseSession;, m( O  S& h/ ]  y3 x) t  C

/ r( T+ O3 B( Z  `/ s% c3 l  D 如果配置不对,getCurrentSession() 会出错。但是不会引起application 不稳定,查查别的地方吧。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT-7, 2026-12-3 14:26 , Processed in 0.266073 second(s), 15 queries , Gzip On, APC On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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