Hi all,
I have some code which looks like this:
Code:
class Person {
@Valid
Set<Address> addresses
}
class Address {
@NotEmpty
@Length(max = 12)
String streetName
@NotEmpty
String city
}
What I want to accomplish is to validate that all addresses have a valid streetName. Validating the complete object works without any problems by using the following code:
Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
validator.validate(person);
However, what I want to do is this:
Code:
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
validator = factory.getValidator();
validator.validate(person, "address.streetName")
"address.streetName", however, doesn't work, because Hibernate thinks my address is a set without a streetName, which is correct. What I also tried was:
"address[].streetName", but then Hibernate complains with an error: "Property path must provide index or map key". If I add such a thing:
"address[0].streetName", it works, but only for the first item in the set, but not when the set is empty or there are two or more items in the set.
So, I was wondering: how do I get this work and how do I validate all the streetNames of all the addresses. Any help would be greatly appreciated!
Kind regards,
Erik Pragt