Java Reference
In-Depth Information
@Column(name = "ID")
private BigDecimal id;
@Size(max = 200)
@Pattern(regexp="", message="Invalid Address")
@Column(name = "ADDRESS1")
private String address1;
@Size(max = 200)
@Column(name = "ADDRESS2")
private String address2;
@Size(max = 250)
@Column(name = "CITY")
private String city;
@Size(max = 2)
@Column(name = "STATE")
message="Invalid State")
private String state;
@Size(max = 10)
@Column(name = "ZIP")
message="Invalid Zip Code")
private String zip;
@Column(name = "START_DATE")
private Date startDate;
@Column(name = "NOTES")
private String notes;
private AuthorBeanValidation author;
As you can see, the @Size , @Pattern , and @NotNull constraint annotations are specified on various fields
within the example entity class. These annotations check to ensure that the values entered for these fields adhere
to the specified rules, namely, that the size does not exceed a certain limit, a String matches a specified pattern,
and a String is not empty, respectively. This example barely scratches the surface of the types of validation that are
possible; for an in-depth tutorial on bean validation or for detailed documentation on the constraint annotations,
please refer to the online documentation. This chapter aims to cover the new additions in the Bean Validation 1.1
release, but it will compare those changes with the previous functionality, where possible.
Constraint Validation Annotations
Annotations are the heart of the Bean Validation API because they are used to decorate any fields, methods, or classes
that are being validated. By utilizing annotations, the validation can be specified in a declarative manner, rather than
by coding conditional logic by hand. The Bean Validation API comes prepackaged with some constraint validation
annotations that are most commonly used. Table 6-1 includes an overview of the full list of built-in constraint
annotations that can be used to perform validation, along with a description of what they validate.
Search WWH ::

Custom Search