首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate双向照射

2012-10-27 
Hibernate双向映射今天查阅了些关于Hibernate一对多映射的文章,基本可以总结为:将多端设置为主控方(invers

Hibernate双向映射

今天查阅了些关于Hibernate一对多映射的文章,基本可以总结为:将多端设置为主控方(inverse = false),可以优化性能。网上形象的比喻是,如果要让国家领导人记住全国人民的名字,估计花个几十年也不可能,但要让全国人民知道国家领导人,可就不需要那么多时间了。

?

又见Hibernate官方annotations文档关于双向映射的描述:

Since many to one are (almost) always the owner side of a bidirectional relationship in the JPA spec, the one to many association is annotated by @OneToMany(mappedBy=...)

?

将one to many端声明 mappedBy,便等价于将多端设置为 主控方 。


To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is not optimized and will produce some additional UPDATE statements.

如果去掉 mappedBy元素,并在 many to one端设置 insertable和 updatable为false, one-to-many将做为主控方,但这样将产生多余的update语句不能达到优化的目的。

热点排行