如何使用注释应用唯一约束

2024-06-21

@Column(name = "userId")
    @UniqueConstraint
    private Integer userId;

我正在使用这些注释将数据输入数据库表。 我想让 userId 字段成为唯一字段。但是当我这样做时,它向我显示错误@UniqueConstraints is disallowed for this location.


@Column(name = "userId",unique=true)

或者如果它是生成的数据库ID http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/#entity-mapping-identifier你也可以这样做

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用注释应用唯一约束 的相关文章

随机推荐