liveBook · Manning

JavaBean Validation API

As explained in Java Persistence with Spring Data and Hibernate epub

Bean Validation is a Java specification for declaring and evaluating constraints on object properties and method parameters.

JavaBean Validation declares integrity rules on domain-model properties and makes them reusable across application layers. Annotations express constraints such as non-null values, string length, regular-expression patterns, and numeric or date ranges instead of repeated conditional checks. The same rules can support presentation and persistence validation, while the SQL database remains the final validator of durable data. section 3.3 section 3.3.2

Use the API to:

  • Declare constraints directly on Java fields or other model elements using validation annotations. section 3.3
  • Expose property paths and localized or customized messages for failed constraints. section 3.3.2
  • Integrate validation automatically with JPA persistence providers when constrained persistent data is stored. section 3.0

Constraining an auction item

An Item can require a non-null name containing 2–255 characters and require auctionEnd to be in the future. Creating a Validator and validating an instance returns ConstraintViolation objects; an auctionEnd set to the current date produces a violation whose property path is auctionEnd.

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Defines declarative constraints and demonstrates programmatic violation inspection, while deferring exhaustive constraint catalogs and implementation internals.
Examples
Uses Item, User, and Log entities with NotNull and Size constraints, plus a future auction-end date and Validator test.
What it assumes
Assumes core Java domain classes and persistence concepts, while teaching constraint declaration and object validation directly.
What you can do after
Apply it via validation annotations and Validator APIs to detect invalid domain objects before persistence.
How it connects
Connects domain models, JPA, Hibernate Validator, ORM metadata, SQL database constraints, and localized error messages.

Also explained in

Compare how 2 books explain JavaBean Validation API →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.