I want to write a class validation. But the following does not result in an error. Why?

   class TestVO {
        @AssertTrue
        public boolean testDefault() {
            return false;
        }
    }

    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    errors = validator.validate(new TestVO());
    assertTrue(!errors.isEmpty()); //this fails. there are no errors! Why?
有帮助吗?

解决方案

To answer my own question, as this is probably usefull as knowledge base: hibernate validations do ONLY work on get() methods. So modifying above to getTestDefault() works.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top