1
votes

I am experiencing some strange behaviour with Hibernate Validator 6.0.9.Final when validating an object. Given the following POJO:

public class Log {
    private Long uid;

    @javax.validation.constraints.NotEmpty
    @javax.validation.constraints.NotNull
    private String value;
    private long reference;
    private String type;
    private String createdDt;
    private String createdBy;
    private Boolean actioned;
    private Long dxr;

    // Constructors..

    // Getters and setters...

    // Equals and hashcode overrides...
}

Now, if I validate the entity using a new instance JUnit test I get the following output:

@Test
public void test() {
    Log cLog = new Log();

    ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory();
    Validator beanvalidator = validatorFactory.getValidator();
    Set<ConstraintViolation<CommunicationLog>> constraintViolations = beanvalidator.validate(cLog);

    System.out.println(constraintViolations);
}

[ConstraintViolationImpl{interpolatedMessage='must not be null', propertyPath=value, rootBeanClass=class Log, messageTemplate='{javax.validation.constraints.NotNull.message}'}, 
ConstraintViolationImpl{interpolatedMessage='must not be empty', propertyPath=value, rootBeanClass=class Log, messageTemplate='{javax.validation.constraints.NotEmpty.message}'}]

Which is fine. However, if I run this same code on a Hibernate/Jersey project, only the @NotNull validation runs. I cannot seem to get the @NotEmpty validator to run on the object.

enter image description here

I have tried removing the @NotNull validator (as the @NotEmpty validator takes care of it) but I left it on for completeness to demonstrate that the @NotEmpty validator is not returning anything in the image above.

I do not understand why it is not running when deployed to a web project but works fine when running under a JUnit test. Is there something I am missing here?

1

1 Answers

0
votes

Okay, so I have resolved this. I hadn't realised that I had deployed the project to the wrong server. I had deployed it to a Payara 4.1.1.171 server instead of a Payara 5.181 server. However, I would have expected some kind of information to have been displayed - perhaps when deploying.