In this tutorial, we will see what is configuration in hibernate.

Hibernate is a hibernate configuration property. It is used to validate and exports schema DDL to the database when the SessionFactory is created.

If we want to make use of it, we should have to pass the appropriate values to the hibernate.cfg.xml like below.


<property name="">value</property>


By defining the property, we can execute the DDL (Data Definition Language) commands from the hibernate framework, while creating the SessionFactory itself.

The property of Hibernate either creates or validates a database table.

The possible values for

  • create
  • validate
  • update
  • create-drop

Syntax :

<?xml version="1.0" encoding="UTF-8"?>
      <property name="">validate/create/update/create-drop</property>
      <property name="" value="validate/create/update/create-drop" />
</hibernate-configuration> Create :

If the value is CREATE then the hibernate first drops the existing tables data and structure, then creates new tables and executes the operations on the newly created tables.

<property name="">create</property>

The only problem with the value “create” is, we lose existing table data. Validate :

If the value is validate then hibernate only validates the table structure- whether the table and columns have existed or not. If the table doesn’t exist then hibernate throws an exception.

Validate is the default value for

<property name="">validate</property> update :

If the value is update then, Hibernate checks for the table and columns. If a table doesn’t exist then it creates new tables and where as if a column doesn’t exist it creates new columns for it.

<property name="">update</property>

But in the case of value “update” hibernate doesn’t drop any existing table, so that we don’t lose existing table data. create-drop :

If the value is create-drop then, Hibernate first checks for a table and do the necessary operations and finally drops the table after all the operations were completed.

<property name="">create-drop</property>

The value “create-drop” is given for unit testing the hibernate code.

Here is a complete (validate,create,update,create-drop) example: Create Example:

Create Pojo class :
package com.otp.hibernate.pojo;

public class Student {
    private int studentId;
    private String studentName;
    private String address;

    public int getStudentId() {
        return studentId;

    public void setStudentId(int studentId) {
        this.studentId = studentId;

    public String getStudentName() {
        return studentName;

    public void setStudentName(String studentName) {
        this.studentName = studentName;

    public String getAddress() {
        return address;

    public void setAddress(String address) {
        this.address = address;


Create Hibernate Mapping File : student.hbm.xml

    <class name="com.otp.hibernate.pojo.Student" table="student">
        <id name="studentId" column="sId">
            <generator class="increment"/>
        <property name="studentName" column="name2" />
        <property name="address" column="address" />

Hibernate configuration file: hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://localhost:3306/onlinetutorialspoint</property>
      <property name="connection.username">root</property>
      <property name="connection.password">123456</property>
      <property name="">create</property>
      <mapping resource="student.hbm.xml" />

Run the Application :
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import com.otp.hibernate.pojo.Student;

public class Main {
  public static void main(String[] args) {
    Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder()
    SessionFactory factory = configuration.buildSessionFactory(;
    Session session = factory.openSession();
    Transaction transaction = session.beginTransaction();
    Student student = new Student();
    student.setStudentName("Chandra Shekhar");
    System.out.println("Transaction Completed !");

By running the above program, we can see the database output like below. Output : <div_class=”post_pic”> Create-Example-min


Happy Learning 🙂

Download Example