Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate-->Column.unique用于非键字段_Hibernate_Jpa - Fatal编程技术网

Hibernate-->Column.unique用于非键字段

Hibernate-->Column.unique用于非键字段,hibernate,jpa,Hibernate,Jpa,这是为了寻找验证,而不是一个问题: Hibernate的@Column.unique检查并确保列条目在JPA级别的唯一性。 这里的列可以是任何列,不一定是键或复合键的一部分 @Column.unique在非键字段上运行正常--检查字段值,如果它已经在表中,则不插入它,这是我所期望的。 Hibernate正在注释@column(unique=true)时向列添加索引,这也很好 但是,@Column.unique读起来像是用于键字段 (Optional) Whether the property i

这是为了寻找验证,而不是一个问题:

Hibernate的
@Column.unique
检查并确保列条目在JPA级别的唯一性。 这里的列可以是任何列,不一定是键或复合键的一部分

@Column.unique
非键字段上运行正常--检查字段值,如果它已经在表中,则不插入它,这是我所期望的。 Hibernate正在注释
@column(unique=true)
时向列添加索引,这也很好

但是,
@Column.unique
读起来像是用于键字段

(Optional) Whether the property is a unique key. This is a shortcut for the UniqueConstraint annotation at the table level and is useful for when the unique key constraint is only a single field. This constraint applies in addition to any constraint entailed by primary key mapping and to constraints specified at the table level. 
我想知道我是否遗漏了什么——我是否会在以后遇到麻烦

ps:我知道使用hibernate的唯一约束 正在确保列条目的唯一性 在JPA级别——并且不能确保它在数据库本身的下面。 这不是问题

pps;我还知道在
@Table
中使用
@UniqueConstraint
属性作为替代方法。 那也不是我想要的。它在桌上做同样的事情


蒂亚

据我所知,
javax.persistence.Column
注释的
unique
属性在生成DDL时使用

这意味着,若您试图从映射的类创建数据库模式,那个么只要该属性存在并设置为true,惟一约束就会添加到数据库中相应的列中

然而,根据JPA规范,它在应用程序运行时并没有任何影响