为什么连接表更好

为什么连接表更好

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

问题描述

在本文档中(向下滚动到单向部分):

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

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections

它说与连接表的单向一对多关联比仅在拥有的实体中使用外键列更受欢迎.我的问题是,为什么它更受欢迎?

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.

连接表将连接解耦,因此拥有的表不知道父表,从而允许设计优雅地缩放.

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 单向一对多关联 - 为什么连接表更好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 03:58