java - inverseJoinColumns 是强制的吗?

标签 java hibernate

在 Hibernate 中创建 @ManyToMany() 关联时是否应该定义 inverseJoinColumn?或者 Hibernate 能够根据某些字段名称定义它的值?

joinColumns 怎么样?

最佳答案

是的。 @JoinTable 中的 joinColumnsinverseJoinColumns 都是可选的,这意味着如果您没有定义它们,则将使用一些默认值。据其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/

相关文章:

java - 将无状态 session bean 注入(inject) Seam 2.2 中的 EntityHome 派生后引发空指针异常

mysql - 使用 registerColumntype for hibernate 在 MySQL 中使用 mediumtext

java - (学生)使用 while 循环捕获并重新提示无效的用户输入

Java - UnixFileSystem - 列表如何对 child 进行排序?

Java - 无法读取 ØÖ(特殊字符)并打印它

java - 使用 Hibernate Criteria 时,类型 List 的表达式需要未经检查的转换以符合 List<Student>

java - SQL 语句转换为 hibernate 标准(具有 count 子句)

java - 如何使用Google Fit API记录客户端进行数据类型.TYPE_LOCATION_SAMPLE的后台收集?

java - Apache POI : Open Template, 写入,另存为。崩溃并创建损坏的文件

java - Spring Data JPA(CrudRepository)-BeanCreationException : Could not autowire field