Search code examples
hibernatevalidationbean-validationhibernate-validator

Validating objects integer property with hibernate validator


I want to validate attribute abc using hibernate validator to check if its null or not.

class A {
@NotNull
private B meta;
}

class B {
@NotNull(message = "missing field")
private int abc;
}

When I try to insert data of my pojo class A without having abc field in it, it still accepts it without validating it. How can I get "missing field" error since I'm not passing abc attribute at all?

If I don't pass abc attribute at all, I want error: "missing field", how can this be done?


Solution

  • I found my own answer. Use Integer object and things starts working & also have @Valid tag in class A.