Hibernate Validation

Hibernate Java - Hibernate Open Source ORM tool in Java What is difference between Hibernate 4 and 5? Hibernate 5.3 features Hibernate 5 JPA Configuration Hibernate 5 persistence.xml example Hibernate 5 JPA Tutorial Hibernate and JPA Example How properties of a class are mapped to the columns of a database table in Hibernate? Hibernate 5 Annotations Maven dependency Hibernate 5 annotationconfiguration Doctype Hibernate-configuration 5 Hibernate 5 Dialect Hibernate 5 configuration dtd Hibernate 5 Hello World Getting started with Hibernate 5 Hibernate 5.2.10 jar Download Hibernate 5.2.10 Maven Dependency Hibernate 5 Maven Dependency Hibernate 5 native query example Hibernate 5 query deprecated When should you use Hibernate? What's new in Hibernate 5? How much time it takes to learn Hibernate? Hibernate envers custom revinfo table Hibernate 5 Envers Hibernate Envers get all revisions Hibernate Examples Hibernate 5 build SessionFactory Example Hibernate 5 SessionFactory Example Hibernate 5 Annotation Example How to download Hibernate 5.x? Hibernate 5 Features Hibernate 5 Tutorials Learning Hibernate ORM - Free Training/Tutorial videos of Hibernate ORM with Java How to write hello world example program in Hibernate? How to create one to one relationship in Hibernate 4 with Annotation? How to calculate minimum in Hibernate using the min() Function Hibernate ORM 4.2.21.Final Released - Create CURD application in latest Hibernate Hibernate ORM 4.2.21 Tutorial - Learn Hibernate ORM Framework Hibernate Error: Failed to create sessionFactory object.java.lang.NoClassDefFoundError

Hibernate Validation

In this tutorial we will describe how to validate you application in hibernate.

In this tutorial we will describe how to validate you application in hibernate.

Hibernate Validation

In this tutorial we will describe how to validate you application in hibernate.

Hibernate Validation  : Validation is the concept to check whether your data is valid or not. Data validation is very common and important process for any application.
Validation is required in presentation layer as well as persistent layer. It is wastage of time to apply validation in each layer.
Hibernate provides very strong annotations validation source. It works directly with your domain model. It reduces overhead of applying validation in each layer.

You can use constraint its java annotation for validation. Now we are going to describe how to annotate an object with these annotation.

Example:  In this example we are using most of validation constraint to validate name, roll, email.

@NotEmpty- checks the element not be empty. It is defined in org.hibernate.validator.constraints.NotEmpty class .

@NotNull - Checks the element not null. It is defined in javax.validation.constraints.NotNull class.

@Max(N) - checks the max length not exceed to 'N'. It is defined in javax.validation.constraints.Max class.

@Min(N) -checks the length not less than 'N'.  It is defined in javax.validation.constraints.Min class.

@Email- Checks the inputted element is in valid email format.  It is defined in javax.validation.constraints.Email class.

package net.roseindia.student;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

public class Student {

@NotEmpty(message = "Please Specify Name")
private String name;

private Integer roll;
private String gender;
private String country;
private String community;

@Email(message = "Enter valid email id")
private String email;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

public Integer getRoll() {
return roll;

public void setRoll(Integer roll) {
this.roll = roll;

public String getGender() {
return gender;

public void setGender(String gender) {
this.gender = gender;

public String getCountry() {
return country;

public void setCountry(String country) {
this.country = country;

public String getCommunity() {
return community;

public void setCommunity(String community) {
this.community = community;

public String getEmail() {
return email;

public void setEmail(String email) {
this.email = email;



Click here to download complete source code