Movatterモバイル変換


[0]ホーム

URL:


ORM
AboutReleasesDocumentationQuicklyMigration guidesBooksProcessorToolingEnversContributePaid support
Source codeIssue trackerSecurity issueForumCIRoadmap
Search
AboutReleasesDocumentationMigration guidesMore resourcesRoadmapContributeToolingPaid supportFAQ
Source codeIssue trackerSecurity issueForumWikiCI
Validator
AboutReleasesDocumentationMigration guidesRoadmapContributeToolingPaid supportFAQ
Source codeIssue trackerSecurity issueForumCI
Reactive
AboutReleasesDocumentationContributePaid support
Source codeIssue trackerSecurity issueForumCI
Repositories
AboutReleasesDocumentationQuickly
Source codeIssue trackerSecurity issue
Others
Community
CommunityGovernanceCommonhaus - MembershipCommonhaus - Joining FAQContribute - GuidelinesContribute - Set up IntelliJ IDEAContribute - Set up Eclipse IDEContribute - Build Hibernate ORMTeamContributors to ORMContributors to SearchContributors to ValidatorContributors to ReactiveContributors to ToolsContributors to OGMCorporate contributorsCompatibility policyMaintenance policyLicensesKeys
BlogForumsFollow us
HibernateMenu
Hibernate
ORMSearchValidatorReactiveRepositoriesOthers
BlogForumsCommunityFollow us

Hibernate Validator

The Bean Validation reference implementation.

Express validation rules in a standardized way using annotation-based constraints and benefit from transparent integration with a wide variety of frameworks.

AboutDocumentationMigration guidesRoadmapContributeToolingPaid supportFAQ
Source codeIssue trackerSecurity issueForumCI

Released under theASL v2

Validation across multiple layers

Hibernate Validator expresses constraints using annotations.

publicclassCar {

@NotNull
privateString manufacturer;

@NotNull
@Size(min =2, max =14)
privateString licensePlate;

@Min(2)
privateint seatCount;

// ...
}

If necessary, the constraints may be overridden in XML.

Such constraints are not tied to a specific architectural tier, programming model, or framework.Constraints might apply to entity classes, Jakarta Datarepository methods, or Jakarta RESTful web service endpoints.And Validator is not tied to the server—​it works just as well for client-side Java programming.

Bean Validation reference implementation

Hibernate Validator is the reference implementation for theBean Validation specification.Indeed, the original specification was inspired by an early version of Hibernate Validator.

Bean Validation is an integral part of the Jakarta platform, incorporated by the Persistence, Data, RESTful Web Services, MVC, and Faces specifications, and by that black sheep of the Hibernate family,CDI.

Programmatic or automatic constraint validation

Constraints may be validated programmatically, but many Java frameworks and libraries—​including Hibernate ORM—​feature built-in support for Bean Validation, making it easy to enforce the constraints completely declaratively.

For example, a constraint is validated automatically if it applies to:

  • a field of an entity class,

  • a parameter of a repository method, or

  • a parameter of a RESTful web service endpoint.

To see all this in action, you can try outHibernate Validator in Quarkus.

Custom constraints

The Bean Validation standard specifies a range of predefined constraint types, and Hibernate Validator adds even more, even including some country-specific constraint types such as@TituloEleitoral.

But the true power of Bean Validation lies in how easy it is to definecustom constraints precisely capturing the semantics of application-specific types.

Rich metadata API

The Bean Validationmetadata API facilitates tooling integration and metaprogramming.Naturally, Hibernate Validator goes beyond the spec.Theprogrammatic constraint configuration API allows constraints to be created programmatically.

Compile-time type safety

The annotation-based approach is by nature quite type safe, but there’s even anannotation processor which raises compilation errors when constraint annotations are used incorrectly, for example, if the@Past annotation is applied to a field of typeString.

Integration with Hibernate ORM

Hibernate ORM not only validates constraints automatically before writing to the database; it even adjusts the DDL generated by the schema management tooling to reflect certain constraints such as@Size,@NotNull,@NotBlank,@Max,@Min, and@Digits.

Latest news

Other news

Projects

Follow us

Contribute and community

Back to top

[8]ページ先頭

©2009-2025 Movatter.jp