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
