Hardy,
Many thanks for the help (and my apologies for my delayed response)... I'm using Validator 3.0-JBoss-4.0.2 (as included with Glassfish 3 JEE 6 version).
Quote:
That said, your example seems a little inconsistent. You are talking about City, but the class you posted is PointOfInterest.
Quite right, I was trying to obtain a forum-friendly example by paring down my actual code, and apparently I made some mistakes in my search-and-replace. PointOfInterest is the actual class name (just rolls off the tongue, doesn't it?), not City. The propertyPaths I posted, however, are exactly as they appeared on the ConstraintViolations I got (but see below).
Quote:
Also in the property path of the violation I would expect an index, eg name[0].
Indeed, once I called validator.validate(poi), not only did I get the additional ConstraintViolation I was looking for, but the propertyPaths changed. Here's what errors.toString() gives me now:
Code:
[ConstraintViolationImpl{interpolatedMessage='size must be between 2 and 250', propertyPath=names[1].name, rootBeanClass=class com.my.poi.domain.PointOfInterest, messageTemplate='{javax.validation.constraints.Size.message}'}, ConstraintViolationImpl{interpolatedMessage='size must be between 2 and 250', propertyPath=names[0].name, rootBeanClass=class com.my.poi.domain.PointOfInterest, messageTemplate='{javax.validation.constraints.Size.message}'}]
So I guess my problem does stem from the JPA/Hibernate integration. What can I do to work around this? Call validator.validate(object) manually in my PointOfInterestService's save() method? (I'd like the validation to be automatic if possible.)
hardy.ferentschik wrote:
Hi,
You should get two violations. Which version of Validator are you using. To help narrowing down you should try to validate a City instance directly and bypass the JPA/Hibernate integration. Try something like this to get a Validator instance:
Code:
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
Set<ConstraintViolation<City>> violations = validator.validate(city);
That said, your example seems a little inconsistent. You are talking about City, but the class you posted is PointOfInterest. Also in the property path of the violation I would expect an index, eg name[0].
Once we isolate the problem we can go further. Maybe you could also create a testcase which we could use to investigate the problem.
--Hardy