Skip to content
Advertisement

hibernate validator throws exception ValidationException: HV000028 for @Past annotation

I am validating an entity with a hibernate validator in a spring boot project. I got an exception for the Date validator @Past . I faced javax.validation.ValidationException: HV000028: Unexpected exception during isValid call

This is the dependency I have in my gradle.build file

implementation 'org.springframework.boot:spring-boot-starter-validation'

The following my a similar entity I have

@NoArgsConstructor
@Data
public class Person{
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
  
    @Column(name = "FIRST_NAME")
    @NotEmpty(message = "ENTER REQUIRED FIELDS - FIRST NAME")
    private String firstName;
    @Column(name = "LAST_NAME")
    @NotEmpty(message = "ENTER REQUIRED FIELDS - LAST NAME")
    private String lastName; 
    @Column(name = "BIRTH_DATE")
    @Past(message = "PLEASE ENTER A VALID DATE ")
    private Date birthDate;    

}

This is a log trace

2020-10-25 13:09:11.421 DEBUG 21952 --- [nio-8080-exec-5] o.s.web.servlet.DispatcherServlet        : Completed 500 INTERNAL_SERVER_ERROR```


Advertisement

Answer

This is for anyone having the same issue as mine. My issue was the Date objects were from java.sql.Date. I changed them to java.util.Date now the validation works.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement