在 Hibernate 中创建 @ManyToMany() 关联时是否应该定义 inverseJoinColumn?或者 Hibernate 能够根据某些字段名称定义它的值?
joinColumns 怎么样?
最佳答案
是的。 @JoinTable
中的 joinColumns
和 inverseJoinColumns
都是可选的,这意味着如果您没有定义它们,则将使用一些默认值。据其javadoc ,默认值与 @JoinColumn
具有相同的默认设置,即:
The concatenation of the following: the name of the referencing relationship property or field of the referencing entity; ""; the name of the referenced primary key column. If there is no such referencing relationship property or field in the entity, the join column name is formed as the concatenation of the following: the name of the entity; ""; the name of the referenced primary key column.
但我不会依赖这些默认值,而是显式地为它们配置一个显式值,以便其他开发人员也可以更轻松地理解代码,因为我认为大多数开发人员不想关心和记住这样的默认逻辑。
关于java - inverseJoinColumns 是强制的吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56927787/