Hibernate的单向一对多关联 - 为什么一个连接表更好吗? [英] Hibernate unidirectional one to many association - why is a join table better?

查看:122
本文介绍了Hibernate的单向一对多关联 - 为什么一个连接表更好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个文件(向下滚动到单向部分):

In this document (scroll down to the Unidirectional section):

<一个href=\"http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections\">http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections

它说,有一个连接表单向的一对多关联是在拥有实体只使用一个外键列多preferred。我的问题是,为什么很多preferred?

it says that a unidirectional one-to-many association with a join table is much preferred to just using a foreign key column in the owned entity. My question is, why is it much preferred?

推荐答案

考虑到在所有的实体类型也可以由另一位家长实体类型所拥有的情况。你把外键引用中拥有的表到两个父表?如果你有三个父类型?它只是不扩展到大型的设计。

Consider the situation where the owned entity type can also be owned by another parent entity type. Do you put foreign key references in the owned table to both parent tables? What if you have three parent types? It just doesn't scale to large designs.

一个加入表解耦加入,使拥有的表没有父表(S)方面的知识,使设计优雅的规模。

A join-table decouples the join, so that the owned table has no knowledge of the parent table(s), allowing the design to scale elegantly.

这篇关于Hibernate的单向一对多关联 - 为什么一个连接表更好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆