The following code does not yield any invalid values even though I am filling the model with invalid values.
private static ClassValidator<User> userValidator = new ClassValidator<User>(User.class);
InvalidValue[] errors = userValidator.getInvalidValues(user);
List<String> err = new ArrayList<String>();
for (InvalidValue invalidValue : errors) {
System.out.println(invalidValue.getMessage());
}
Adding the User entity class as requested in the comments.
@Entity(name = "User")
@NamedQueries({
@NamedQuery(name = MWQueries.nqAllUsers, query = "from User"),
@NamedQuery(name = MWQueries.nqUserById, query = "from User where id = ?")
})
public class User implements Serializable {
private static final long serialVersionUID = -5013553611664469461L;
private Long id;
private String userName;
private String email;
private Role role;
private @XStreamOmitField String passWord;
public User() {
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Column
@Length(min = 6, max = 20)
@NotBlank
@NotEmpty
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
@Column
@Length(min = 6)
@NotBlank
@NotEmpty
@JsonIgnore
public String getPassWord() {
return passWord;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
@Column
public Role getRole() {
return role;
}
public void setRole(Role role) {
this.role = role;
}
@Column(unique = true)
@Email
@NotBlank
@NotEmpty
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
The only hint I can give you, is to try it a bit different. If this test validation works, than the problem is somewhere in the way you use the validator. If it does not works, then the problem is somewhere in your entity