0

I have the following class:

class Foo
{
   @Valid
   private Bar bar;
}

In Bar, I have:

class Bar
{
   @NotEmpty
   private String baz;
}

I want to validate the property bar.baz from foo. But when I try validateProperty() and pass the string bar.baz as the property name, I get an error that there's no such property. Is it not possible to validate child properties in this way?

2
  • Where is the "child" mentioned in your question title? I don't see the keyword extends anywhere. Is this an oddity of hibernate? Commented Mar 10, 2014 at 21:36
  • 1
    @Rusher Sorry, by child I meant contained within the first class. As Bar is contained within Foo in this case. Commented Mar 10, 2014 at 21:55

1 Answer 1

1

As per Bean Validation specification the property must be a direct property of the bean you are validating:

Set> validateProperty(T object, String propertyName, Class... groups) validates a given field or property of an object. An IllegalArgumentException is thrown when validateProperty() is called and object is null or propertyName is null empty or invalid or null is passed to the varargs groups parameter. The property name is the JavaBeans property name (as defined by the JavaBeans Introspector class). This method implements the logic described in Section 4.6, “Validation routine” but only to the given property. @Valid is not honored by this method. This method is useful for partial object validation.

That said, Hibernate Validator supports property paths as you can also see here. To help any further, you would need to post the full stack trace.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.