liveBook · Manning

Validation-mode

As explained in Java Persistence with Spring Data and Hibernate epub

validation-mode is a JPA persistence configuration element that controls whether a provider automatically performs Bean Validation.

validation-mode configures whether a JPA provider automatically applies Bean Validation to persistent objects before database inserts and updates. section 3.3.2

Choose a persistence.xml mode according to provider availability and enforcement requirements:

  • AUTO enables validation only when a Bean Validation provider, such as Hibernate Validator, is available on the application classpath. section 3.3.2
  • CALLBACK always enables validation and causes deployment to fail when a Bean Validation provider is missing. section 3.3.2
  • NONE disables automatic validation by the JPA provider. section 3.3.2

Constraint-driven persistence

An entity can declare @NotNull and @Size on a name field and @Future on an auctionEnd field. Automatic validation rejects invalid state with ConstraintViolationException before persistence operations complete. section 3.3.2

Listing 3.6 Applying validation constraints on Item entity fields
Path: Ch03/validation/src/main/java/com/manning/javapersistence/ch03
 /validation/Item.java
 
import javax.validation.constraints.Future;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.Date;
 
public class Item {
    @NotNull
    @Size(
            min = 2,
            max = 255,
            message = "Name is required, maximum 255 characters."
    )
    private String name;
 
    @Future
    private Date auctionEnd;
}

Inspect a concrete entity whose fields define the constraints consumed by automatic validation. section 3.3.2

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains provider discovery, lifecycle validation, deployment failure, and disabling behavior, but defers validator feature details.
Examples
Uses Item fields annotated with @NotNull, @Size, and @Future to demonstrate persistence-time constraint checking.
What it assumes
Assumes JPA persistence configuration and Bean Validation providers; teaches provider discovery and automatic validation behavior.
What you can do after
Operate/configure automatic validation by selecting AUTO, CALLBACK, or NONE in persistence.xml.
How it connects
Connects Bean Validation, Hibernate, Hibernate Validator, persistence.xml, entity constraints, and ConstraintViolationException.

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.