Este conteúdo não está disponível no idioma selecionado.

1.2. Built in constraints


Hibernate Validator comes with some built-in constraints, which covers most basic data checks. As we'll see later, you're not limited to them, you can literally in a minute write your own constraints.
Expand
Table 1.1. Built-in constraints
Annotation Apply on Runtime checking Hibernate Metadata impact
@Length(min=, max=) property (String) check if the string length match the range Column length will be set to max
@Max(value=) property (numeric or string representation of a numeric) check if the value is less than or equals to max Add a check constraint on the column
@Min(value=) property (numeric or string representation of a numeric) check if the value is more than or equals to min Add a check constraint on the column
@NotNull property check if the value is not null Column(s) are not null
@NotEmpty property check if the string is not null nor empty. Check if the connection is not null nor empty Column(s) are not null (for String)
@Past property (date or calendar) check if the date is in the past Add a check constraint on the column
@Future property (date or calendar) check if the date is in the future none
@Pattern(regex="regexp", flag=) or @Patterns( {@Pattern(...)} ) property (string) check if the property match the regular expression given a match flag (see java.util.regex.Pattern ) none
@Range(min=, max=) property (numeric or string representation of a numeric) check if the value is between min and max (included) Add a check constraint on the column
@Size(min=, max=) property (array, collection, map) check if the element size is between min and max (included) none
@AssertFalse property check that the method evaluates to false (useful for constraints expressed in code rather than annotations) none
@AssertTrue property check that the method evaluates to true (useful for constraints expressed in code rather than annotations) none
@Valid property (object) perform validation recursively on the associated object. If the object is a Collection or an array, the elements are validated recursively. If the object is a Map, the value elements are validated recursively. none
@Email property (String) check whether the string is conform to the email address specification none
@CreditCardNumber property (String) check whether the string is a well formated credit card number (derivative of the Luhn algorithm) none
@Digits(integerDigits=1) property (numeric or string representation of a numeric) check whether the property is a number having up to integerDigits integer digits and fractionalDigits fractonal digits define column precision and scale
@EAN property (string) check whether the string is a properly formated EAN or UPC-A code none
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat