【发布时间】:2014-04-01 23:56:24
【问题描述】:
这是寻找验证而不是问题:
@Column.unique 的 Hibernate 检查并确保 JPA 级别的列条目的唯一性。
这里的列可以是任何列,不一定是键或组合键的一部分。
@Column.unique 在 non-key 字段上工作正常 - 检查字段值,如果它已经在我期望的表中,则不插入它。
Hibernate 在注释 @Column(unique=true) 上为列添加索引——这也很好。
但是,@Column.unique specs 读起来像是关键字段。
(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 属性作为替代方法。
这也不是我所追求的。它在表级别做同样的事情。
TIA。
【问题讨论】: