@ManyToMany(mappedBy =" foo") [英] @ManyToMany(mappedBy = "foo")

查看:204
本文介绍了@ManyToMany(mappedBy =" foo")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Foo有:

@ManyToMany(mappedBy = "foos")
private Set<Bar> bars

且酒吧有:

@ManyToMany
private Set<Foo> foos

除了表格之外,mappedBy属性的位置对双向关系有何不同被称为foo_bar,或bar_foo;如果没有mappedBy属性,我会得到两个连接表,包括foo_bar和bar_foo。

What difference does the location of mappedBy attribute make to a bi-directional relationship , other than whether table is called foo_bar, or bar_foo; and without the mappedBy attribute I get two join tables, both foo_bar and bar_foo.

推荐答案

文档说:


如果关联是双向的,则一方必须是所有者,一方必须是反向结束(即,更新关联表中的关系值时将忽略它):

If the association is bidirectional, one side has to be the owner and one side has to be the inverse end (ie. it will be ignored when updating the relationship values in the association table):

因此,具有 mappedBy 属性的一方是反向的侧。没有 mappedBy 属性的一方是所有者。

So, the side which has the mappedBy attribute is the inverse side. The side which doesn't have the mappedBy attribute is the owner.

所有者方是Hibernate查看哪一方存在的一方。因此,例如,如果在Bar的foos集中添加Foo,Hibernate将在连接表中插入一个新行。相反,如果你将一个Bar添加到Foo的一组条形图中,则数据库中不会修改任何内容。

The owner side is the side which Hibernate looks at to know which association exists. So, for example, if you add a Foo in the set of foos of a Bar, a new row will be inserted by Hibernate in the join table. If, on the contrary, you add a Bar to the set of bars of a Foo, nothing will be modified in the database.

这篇关于@ManyToMany(mappedBy =&quot; foo&quot;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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