I want to ask how to handle uniquecontraint exception at thymeleaf. To handle excpetion I am using this:
<span th:style="'color:red'" th:if="${#fields.hasErrors('userName')}" th:errors="*{userName}">Name Error</span>
It handles lenght exception and not null, but why it fail with uniqe constraint, my entity looks like this:
@Entity(name = "Users")
@Table(
name = "\"users\"",
uniqueConstraints = {
@UniqueConstraint( name = "users_username_unique", columnNames = "user_name")
}
)
public class Users {
...
@Column(
name = "user_name",
nullable = false,
columnDefinition = "TEXT",
updatable = false
)
@Length(min = 5, message = "*User name is too short")
@NotEmpty(message = "*Enter user name")
private String userName;
...
}