Summary

Bean Validation is a crucial part of the Java EE 7 platform. It does small things and it does them very well as we learnt in this chapter. Bean Validation allows the developer to extend the Java type system in a programmatic fashion through design-by-contract at runtime albeit not at static compilation time. Bean Validation is governed by constraints, which are defined by annotations.

A constraint has an interpreted message property, a group set, and a payload. Constraints can be grouped together in order to perform full or partial validation or specific order evaluation.

In order to execute value object checking with annotated constraints, the application must gain access to the Bean Validation ValidatorFactory instance and then obtain a Validator instance. The advantage of this model means evaluation of constraints is mostly in the control of incumbent applications.

The specification has a set of standard constraints such as @NotNull, @Max and @DecimalMin. The reference implementation Hibernate Validator has the standard set of constraints from the specification, and it supplies additional useful constraints such as @NotEmpty, @Range, and @Email.

Groups of constraints can be ordered. A class-level constraint allows checking of interdependent properties in a value object. Method-level constraint in conjunction with a suitable interception technology allows non-static methods to be evaluated for correctness through their method parameters and associated return values.

Finally, Bean Validation has considerable integration features for CDI, JPA, and JAX-RS technologies and even other containers outside of the Java EE 7 environment.

In the next chapter, we will advance much further into Java Persistence.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.186.143