this is my sample application with it's test. I've defined some constraints on repository as @NotEmpty
. When I want to call this repository I'm getting following issue
javax.validation.ConstraintDeclarationException: HV000141: The constraint org.hibernate.validator.constraints.NotEmpty used ConstraintTarget#IMPLICIT where the target cannot be inferred.
Do I need to implement validator for @NotEmpty
or is this a bug in hibernate or my spring-boot application?
note when I remove @NotEmpty
from return type, it works.
You are running into an interesting corner case here, where for a purely composed constraint it cannot be determined whether it applies to the parameters or the return value of a method. Back in the time of Bean Validation 1.1 we decided to leave it to implementations to handle this case as it's very rare.
Hibernate Validator allows to resolve this case by specifying @SupportedValidationTarget(ValidationTarget.ANNOTATED_ELEMENT)
on the constraint definition. This was added in HV 5.2, but then it seems we forgot to make use of it for @NotEmpty
and potentially other purely composed constraints defined by HV. Could you therefore please file a bug report in our JIRA instance?
Note that you shouldn't have the problem with the @NotEmpty
defined in Bean Validation 2.0 (HV 6.0), as this isn't declared as a purely composed constraint.
Update: this issue has been fixed in Hibernate Validator 6.0.3.Final (and backported to 5.3.6.Final and 5.4.2.Final).