gpt4 book ai didi

java - @ManyToMany(mappedBy = "foo")

转载 作者:IT老高 更新时间:2023-10-28 20:55:50 25 4
gpt4 key购买 nike

Foo 有:

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

而酒吧有:

@ManyToMany
private Set<Foo> foos

除了table是叫foo_bar还是bar_foo之外,mappedBy属性的位置对双向关系有什么不同;如果没有 mappedBy 属性,我会得到两个连接表,foo_bar 和 bar_foo。

最佳答案

The documentation说:

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 属性的一方是所有者。

所有者方是 Hibernate 查看以了解存在哪个关联的一方。因此,例如,如果您在 Bar 的 foo 集合中添加一个 Foo,Hibernate 将在连接表中插入一个新行。相反,如果您将 Bar 添加到 Foo 的 bar 集合中,则不会在数据库中修改任何内容。

关于java - @ManyToMany(mappedBy = "foo"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14111607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com