Validating persistent fields and properties

The integrity of most, if not all, applications depend on the correctness of its data. The Java API for JavaBeans Validation provides a means to validate data through the use of annotations.

This recipe explains this technique by introducing a driver's license entity. The next set of recipes illustrates how to specify constraints on several different types of fields. The last recipe pulls these techniques together and illustrates the use of the javax.validation.Validator class to determine if the constraints were met.

Getting ready

First we will create an entity representing a driver's license and its supporting classes. Once this is working we will enhance the entity to incorporate validation annotations. ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.