如何使用注释应用唯一约束 [英] How to apply unique constraints using annotation
本文介绍了如何使用注释应用唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Column(name = "userId")
@UniqueConstraint
private Integer userId;
我正在使用这些注释将数据输入到数据库表中.我想让 userId 字段成为唯一字段.但是当我这样做时,它向我显示错误 @UniqueConstraints is not allowed for this location.
I am using these annotation for entering data into database table.
i want to make userId field unique field. but when i am doing like it it is showing me error @UniqueConstraints is disallowed for this location.
推荐答案
@Column(name = "userId",unique=true)
或者如果它是一个数据库生成的 ID你也可以这样做
or if its an DB generated ID you can also do this
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
这篇关于如何使用注释应用唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文