Bean validation built-in constraints
Use this information to look up information about Bean Validation API built-in constraints.
The Bean Validation API is supported by constraints that are primarily expressed through annotations. The constraints are added to a class, field, or method of an EJB component. The annotated element value is checked by the constraint.
Constraints can be built in or user defined. Several built-in annotations are available in the javax.validation.constraints package. They are used to define regular constraint definitions and for composing constraints.
The following table is a list of constraints and usage.
Constraint Usage @Null The configuration property decorated with this annotation must have a null value. This constraint accepts any type. @NotNull The configuration property decorated with this annotation must not have a null value. That is, the property is required. This constraint accepts any type. @AssertTrue The configuration property decorated with this annotation must be true. Supported value types are boolean and Boolean. Null elements are considered valid. @AssertFalse The configuration property decorated with this annotation must be false. Supported value types are boolean and Boolean. Null elements are considered valid. @Min The configuration property decorated with this annotation must have a value greater than or equal to the specified minimum. Supported value types are BigDecimal, BigInteger, byte, short, int, long and their respective wrappers. Null elements are considered valid. @Max The configuration property decorated with this annotation must have a value less than or equal to the specified maximum. Supported value types are BigDecimal, BigInteger, byte, short, int, long and their respective wrappers. Null elements are considered valid. @DecimalMin The configuration property decorated with this annotation must have a value higher or equal to the specified minimum. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid. @DecimalMax The configuration property decorated with this annotation must have a value lower or equal to the specified maximum. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid. @Size The configuration property decorated with this annotation must have a value between the specified boundaries (included). Supported value types are String (string length is evaluated), Collection (collection size is evaluated), Map (map size is evaluated), Array (array length is evaluated). Null elements are considered valid. @Digits The configuration property decorated with this annotation must have a value within accepted range. Supported value types are BigDecimal, BigInteger, String, byte, short, int, long and their respective wrappers. Null elements are considered valid. @Past The configuration property decorated with this annotation must have a date in the past. Now is defined as the current time according to the virtual machine. The calendar is used if the compared type is of type Calendar and the calendar is based on the current timezone and the current locale. Supported value types are java.util.Date, java.util.Calendar. Null elements are considered valid. @Future The configuration property decorated with this annotation must have a date in the future. Now is defined as the current time according to the virtual machine. The calendar is used if the compared type is of type Calendar and the calendar is based on the current timezone and the current locale. Supported value types are java.util.Date, java.util.Calendar. Null elements are considered valid. @Pattern The configuration property decorated with this annotation must match the following regular expression. The regular expression follows the Java regular expression conventions java.util.regex.Pattern. Supported type value is String. Null elements are considered valid.
Related concepts
Bean validation in RAR modules Bean Validation
Bean validation troubleshooting tips
Related information:
Troubleshooting bean validation in RAR modules