我创建了两个基于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的定义是否正确?
1条答案
按热度按时间h4cxqtbf1#
在兴趣类中,也声明“var accounts:list”,使用反向Map!