@UniqueConstraint和@Column(unique = true)?@UniqueConstraint和@Column(unique = true)在休眠註釋
例如:
@Table(
name = "product_serial_group_mask",
uniqueConstraints = {@UniqueConstraint(columnNames = {"mask", "group"})}
)
而且
@Column(unique = true)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private ProductSerialMask mask;
@Column(unique = true)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Group group;
注意:在Hibernate 5.4中,當我添加'unique = true'時,索引不會被scheme自動更新器添加。 '@ UniqueConstraint'使它出現。可能是一個錯誤。 – 2017-02-13 22:10:02