JiveJdon Community Forums
在线434人   首页   主题表   培训咨询   标签   精华   查搜   注册    登陆 RSS
首页 » 论坛 » J2EE/JavaEE/JEE/EJB/JSF等技术讨论
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表
???en_US.forumThreadNext.name??? 下一主题
Go 总共有 6 回复 / 1
 发表新帖子   回复该主题贴
newpaul

悄悄话
发表文章: 39
注册时间: 2003年08月05日 01:20
谁能解释一下hibernate 中的Cascades 2003年08月08日 14:58 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
标签列表 hibernate(119)     
谁能解释一下Hibernate 中的Cascades

还有关于proxy的问题
<class name="eg.Order" proxy="eg.Order">
The runtime type of the proxies will be a subclass of Order. Note that the proxied class must implement a default constructor with at least package visibility.

在它的文档上是这么说的

为什么说 代理的类型时order的子类呢 而不是order本身呢?
yehs220

悄悄话
发表文章: 101
注册时间: 2003年01月04日 12:50
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 15:11 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
cascade:级联,用于传播各种操作到关联对象,可选值
all:传播所有
none:不传播任何
delete:传播delete
save-update:传播insert,update,
最新版的Hibernate可能还有更多可选值。

proxy:
你可以load一个对象,看看它的实际类型是什么,再看看它的
继承树及实现接口。
newpaul

悄悄话
发表文章: 39
注册时间: 2003年08月05日 01:20
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 15:20 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
我看了他的文档 但是不太理解 能帮我解释一下吗?

<class name="eg.Order" proxy="eg.Order">
The runtime type of the proxies will be a subclass of Order.
它说这里的proxy是 order 的子类 迷惑


<class name="eg.Cat" proxy="eg.Cat">
......
<subclass name="eg.DomesticCat" proxy="eg.DomesticCat">
.....
</subclass>
</class>
Firstly, instances of Cat will never be castable to DomesticCat, even if the underlying instance is an instance of DomesticCat

这里说 cat 类不能够造成它的子类DomesticCat 迷惑
Cat cat = (Cat) session.load(Cat.class, id); // instantiate a proxy (does not hit the db)
if ( cat.isDomesticCat() ) { // hit the db to initialize the proxy
DomesticCat dc = (DomesticCat) cat; // Error!
....
}

Secondly, it is possible to break proxy ==.

Cat cat = (Cat) session.load(Cat.class, id); // instantiate a Cat proxy
DomesticCat dc =
(DomesticCat) session.load(DomesticCat.class, id); // required new DomesticCat proxy!
System.out.println(cat==dc);
这一段也没明白 这里的break proxy == 是什么意思

However, the situation is not quite as bad as it looks. Even though we now have two references to different proxy objects, the underlying instance will still be the same object:

cat.setWeight(11.0); // hit the db to initialize the proxy
System.out.println( dc.getWeight() ); // 11.0

这里为何 cat 和dc 怎么又是同一个对象呢?? 迷惑



能解释一下吗? 谢谢

newpaul

悄悄话
发表文章: 39
注册时间: 2003年08月05日 01:20
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 15:23 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
相关的 mapping
class name="eg.Order" proxy="eg.Order"


class name="eg.Cat" proxy="eg.Cat"
......
subclass name="eg.DomesticCat" proxy="eg.DomesticCat"
.....
/subclass
/class
yehs220

悄悄话
发表文章: 101
注册时间: 2003年01月04日 12:50
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 15:42 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
如果你为某个class设置了proxy="...",那么Hibernate会在运行时用CGLib生成一个
proxy="..."所指定的这个类的一个子类作为你的那个entity class的proxy。


比如说你为Cat指定proxy="Cat",hibernate会继承Cat,生成一个代理类,就叫CatProxy(我随便取的)吧

同样对DomesticCat,hibernate会继承DomesticCat,生成一个代理类,就叫DomesticCatProxy吧


Cat cat = (Cat) session.load(Cat.class, id); // instantiate a proxy (does not hit the db)
//cat的实际类型就是CatProxy,你可以调用cat.getClass().getName()和cat.getClass().getSuperClass().getName()就知道了

if ( cat.isDomesticCat() ) { // hit the db to initialize the proxy
DomesticCat dc = (DomesticCat) cat; // Error!

//从CatProxy转型到DomesticCat,显然不对
....
}

Secondly, it is possible to break proxy ==.

Cat cat = (Cat) session.load(Cat.class, id); // instantiate a Cat proxy
DomesticCat dc =
(DomesticCat) session.load(DomesticCat.class, id); // required new DomesticCat proxy!
System.out.println(cat==dc);
这一段也没明白 这里的break proxy == 是什么意思

//就是会打出false,cat和de的类型分别是CatProxy和DomesticCatProxy,怎么会相等呢?

However, the situation is not quite as bad as it looks. Even though we now have two references to different proxy objects, the underlying instance will still be the same object:

cat.setWeight(11.0); // hit the db to initialize the proxy
System.out.println( dc.getWeight() ); // 11.0

//这两个proxy的底层是同一个对象
newpaul

悄悄话
发表文章: 39
注册时间: 2003年08月05日 01:20
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 15:50 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
这下彻底明白了!谢谢

还能和我说说在Hibernate中的cache的问题吗

我看文档上说 有这几种Read Only cache,Read / Write cache,Nonstrict Read / Write cache

在具体应用上 怎么使用呢?

yehs220

悄悄话
发表文章: 101
注册时间: 2003年01月04日 12:50
Re: 谁能解释一下hibernate 中的Cascades 2003年08月08日 16:00 到本帖网址 加入本帖到收藏夹 发送到手机 回复该主题
文档中有一些说明呀,我也没实际用过,
Hibernate forum去看看吧
这个主题有 6 回复 / 1Go
???en_US.forumThreadPrev.name??? 上一主题
  Go back to the topic 返回本主题   Go back to the topic listing返回主题列表    返回页首返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache 缓存 DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Seam Spring Struts
正在读取,请等待...
google yahoo 新浪ViVi 365Key网摘 天极网摘 CSDN网摘 添加到百度搜藏 POCO网摘 博采网摘
查询本论坛内 回复超过的热门帖子
     回复该主题贴
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
  每2分种自动备份发贴内容Ctrl-V粘贴取出,提问题前先查询标签列表

RSS 手机阅读 add to google add to yahoo
解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com

anti spam