There are two principle Bean Validation implementations. The main implementation is referred to as the built in Bean Validation and is part of the javax.validation package and the other is the reference implementation provided by Hibernate and is called Hibernate Validator. In this video, examine both implementations and how to take advantage of the features provide by both.
- [Instructor] The Bean Validation API that's packaged with the Java EE platform is contained in a top level package javax.validation. The various parts of the API are in subpackages. The entry point to the API is the javax.validation .validation interface which provides three ways to boost up the API. This is usually done behind the scenes so you don't need to worry about doing it yourself. And the most interesting package is the constraints package which is located underneath the javax.validation package. It is in this package that you will find all the built-in constraints such as the Email constraint, the NotNull constraint and so on.
I'll be using all the constraints in this package throughout this course so you'll get to know them very well. The implementation that comes with the Java EE platform conforms strictly to the JSR specification and provides no more and no less than what the specification requires. The version I will be using in this course is version 2.0 which is packaged with Java EE 8. However another flavor of the Bean Validation API exists called Hibernate Validator. This is a very popular implementation of the JSR and provides more than the specification requires.
It is referred to as the reference implementation which means that it guarantees to provide at least what the specification defines although it actually provides much more. Most notably, it provides more Bean Validation constraints that validate all kinds of data shapes such as credit card numbers, social security numbers, and bar codes. Later on in this course, you'll be getting to use some of these constraints. The top-level package is org.hibernate.validator and provides the bootstrapping capabilities of the API.
The constraints are in the package constraints under the parent package and includes the 22 constraints detailed in the specification and 21 additional constraints. A version of the Hibernate Validator I'll be using in this course is version 6.0 because it aligns with the Bean Validation API version 2.0 and Java EE 8. Take a look at this table. It shows the alignment between Java EE, the Bean Validation API, the Hibernate Validator API, and the minimum version of Java SE you must have configured.
As already mentioned, this course will use Java EE 8, Bean Validation 2.0 and Hibernate Validator 6. However if you are using Java EE 7 or 6, you will still get great value from this course. The only thing you will notice is that not all the constraints I mentioned are available in the versions you are using. Other than that, everything else is valid for whatever version you are using. The Java docs for the Bean Validation API can be found on the Java EE's GitHub account and the Java docs for the Hibernate Validator API can be found on the Hibernate website.
For full information about the Hibernate Validate API, you should visit the URL hibernate.org/validator.
In this course, you can journey through the many constraints that are built into the 2.0 version of the Bean Validation API, as well as the additional constraints provided by the Hibernate Validator 6.0. Learn Bean Validation in a practical way while you build a functioning web application. Instructor Alex Theedom shows how to extend the API with custom constraints and how to internationalize validation failure messages. Plus, learn advanced techniques such as cross-field and cross-parameter validation, and how Bean Validation integrates with other Java EE technologies such as JAX-RS, Java Persistence API (JPA), and JavaServer Faces (JSF). By the end of this course, you will have gained practical experience of using Bean Validation in a real web application and be able to implement what you have learned in your own Java applications.
- What is Bean Validation?
- Applying the built-in constraints
- Applying Hibernate constraints
- Designing custom constraint validators
- Managing and configuring validation failure messages
- Creating custom composite constraints
- Creating custom validation constraints
- Cross-field and cross-parameter validation
- Integration with RESTful web services (JAX-RS)