我有带有两个自定义验证注释@FieldMatch
和@CategoryExists
的类别实体。这是代码:
@Entity
@Table(name = "Category")
@FieldMatch(first = "defaultSrcLanguage", second =
"defaultTargetLanguage", message = "Languages must be different")
@CategoryExists(category="name", message="Category already exists")
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Size(min=2, message="Enter at least 2 characters...")
@Column(name = "name")
private String name;
@OneToOne
@NotNull
private Language defaultSrcLanguage;
@OneToOne
@NotNull
private Language defaultTargetLanguage;
private String defaultTargetSide;
private int defaultCountdownDuration;
// getters and setters
@CategoryExists
检查数据库中是否已存在具有提供名称的类别。如果存在,则显示错误消息:“类别已存在”。在创建新类别时需要。但是在更新类别(即“ Test5”)期间,我不希望总是更改类别名称,而希望更改其他字段,例如defaultSrcLanguage
。顺便说一句,我将收到相同的错误消息“类别已存在”。是否可以禁用注释@CategoryExist
进行更新?也许其他解决方案?