1

我创建了两个基于 Hibernate 的表,它们之间具有多对多的关系。

表格:

@Entity
@Table(name = "Interests")
data class Interest(
    var description: String = "") : PanacheEntity()

@Entity
@Table(name = "Accounts")
data class Account(@field:Id var id: UUID? = null,
                   @ManyToOne(fetch = FetchType.LAZY) var gender: Gender? = null,
                   var birthday: Long = 0,
                   @ManyToMany(fetch = FetchType.LAZY, cascade = [CascadeType.PERSIST])
                   @JoinTable(
                       name = "user_interests",
                       joinColumns = [JoinColumn(name = "user_id")],
                       inverseJoinColumns = [JoinColumn(name = "interest_id")]
                   )
                   var interests: List<Interest> = listOf()) : PanacheEntityBase

在幕后,Hibernate 创建了一个单独的表来保存外键。这是生成的 DDL:

create table user_interests
(
    user_id     uuid   not null
        constraint fkfxfdgodf1o1gxd8offdxrhcwu
            references accounts,
    interest_id bigint not null
        constraint fkdtbf68t9l8ehm46bi6ko45kb5
            references interests
);

问题是,约束后的神秘字符串是什么,DDL 是否正确定义?

4

1 回答 1

2

在 Interest 类中,也使用逆映射声明“var accounts: List”!

于 2020-09-04T22:35:06.507 回答