gpt4 book ai didi

java - hibernate 。如何为字段组合添加唯一索引?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:55:26 32 4
gpt4 key购买 nike

我有以下 hibernate 映射:

@Entity
public class UserPattern {
@Id
@GeneratedValue
Integer id;

@ManyToOne
@JoinColumn(name = "user_id")
User user;

@ManyToOne
@JoinColumn(name = "patern_id")
Pattern pattern;

...
}

hibernate 是否允许添加唯一索引,userpattern 的组合是唯一的?

最佳答案

我认为它会起作用:

@Table(name="UserPattern", 
uniqueConstraints=
@UniqueConstraint(columnNames={"user_id", ""})

@Table(name="UserPattern",  uniqueConstraints={
@UniqueConstraint(columnNames={"user_id", "patern_id"})
})

关于java - hibernate 。如何为字段组合添加唯一索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24673743/

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