Validating string


28-Jan-2015 09:22

In this section we show how to annotate an object model with these annotations.We have to differentiate between three different type of constraint annotations - field-, property-, and class-level annotations.All the validation methods have a var-args parameter which can be used to specify, which validation groups shall be considered when performing the validation.If your model class adheres to the Java Beans standard, it is also possible to annotate the properties of a bean class instead of its fields.Example 2.2, “Property level constraint” uses the same entity as in Example 2.1, “Field level constraint”, however, property level constraints are used..To make things clearer let's have a look at the following example: The Bean Validation API does not only allow to validate single class instances but also complete object graphs.To do so, just annotate a field or property representing a reference to another object with instance is added for each violated constraint.In this chapter we will see in more detail how to use Hibernate Validator to validate constraints for a given entity model.

When using field level constraints field access strategy is used to access the value to be validated.

This means the bean validation provider directly accesses the instance variable and does not invoke the property accessor method also if such a method exists.