如何使用注释应用唯一约束 [英] How to apply unique constraints using annotation
本文介绍了如何使用注释应用唯一约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@Column(名称=用户id)
@UniqueConstraint
私人整数用户id;
我使用这些注释将数据录入数据库表。
我想使用户id字段中的唯一领域。但是当我做喜欢它它显示了我的错误 @UniqueConstraints是不允许的这个位置。
解决方案
@Column(名称=用户id,唯一= TRUE)
或者它的DB生成的<一个href=\"http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier\">ID你也可以做到这一点。
@Id
@GeneratedValue(策略= GenerationType.AUTO)
私人整数ID;
@Column(name = "userId")
@UniqueConstraint
private Integer userId;
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)
or if its an DB generated ID you can also do this
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id;
这篇关于如何使用注释应用唯一约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文