唯一键约束在Spring数据JPA

问题描述:

如何使用弹簧数据JPA使在POJO唯一的字段,我知道该怎么做,使用JPA唯一键约束在Spring数据JPA

参考:multi column constraint with jpa

如果有一种方法,是有可能使用弹簧引导?

使用Spring Data JPA您正在使用JPA,因此您可以使用JPA指定唯一约束。在这方面,Spring Boot或Spring Data没有什么特别之处。

+0

所以你说我们需要使用JPA只让它在春天数据JPA –

+0

独特constraint.Nothing是这个corect? –

使用@UniqueConstraint注释来指定生成的DDL中为主表或辅助表包含的唯一约束。

另外,要确保一个字段值是唯一的,你可以写

@Column(unique=true) 
String myField;