Iaroslav Gutsul
What is value from validation?
What is possible place for validation?
What is right place for validation?
What is correct implementation of
validation?
How to implement … with Hibernate
Validator
 simple bean validation
 simple method validation
 complex bean validation
 custom constrain for validation
What is with Hibernate Validator?
• validation framework based on metadata model (annotations)
• implements JSR 349 (Bean Validation 1.1) specification
• provides under Apache Software License 2.0
How to add Hibernate Validator to my
project?
Required
Optional
Basic bean validation
 Field-level constraints
 Property-level constraints
 Class-level constraints
 Constraint inheritance
Cascade validation with @Valid
Validator methods
Validator#validate()
Validator#validateProperty()
Validator#validateValue()
Built-in constraints
@AssertFalse
@Future
@Max(value=)
@Min(value=)
@DecimalMax(value=,
inclusive=)
@NotNull
@Valid
@Size(min=, max=)
@NotEmpty
@Pattern(regex=, flag=)
Declaring method constraints
 Parameter constraints
 Return value constraints
Cross-parameter constraints
Error Message
default message
custom message source
Grouping constraints
Validation group = java interface
Add group to validation property
Validation with group
Grouping constraints combination
@GroupSequence
@GroupSequenceProvider (PROVIDER)
PROVIDER implements DefaultGroupSequenceProvider<T>
provide list of validation groups based on object stage
@ConvertGroup(from = GROUP_A.class, to = GROUP_B.class)
during validation with group A will be used rules from both
groups
Creating custom constraints
Create a constraint annotation
Implement a validator
Define a default error message
Create a constraint annotation with
default error message
Implement a validator
ConstraintViolation Structure
Interesting Notes
 Fail fast mode
 Boolean composition of constraints in custom constrain
@ConstraintComposition(OR)
CompositionType with its values AND, OR and ALL_FALSE.
Validation of Null by default return true
Thank you!
Questions?

Flexible validation with Hibernate Validator 5.x.