Hibernate Configuration File

What is purpose of Hibernate Configuration File?
Hibernate Configuration File provides below details, which are used by Hibernate Framework. In below description, we are considering connecting to a MySQL database.
hibernate.cfg.xml has below properties.
1. JDBC Driver details
2.Database url
3.Date base credentials
username
password
4.Mapping resource
It is possible to specify one or more mapping resources. Mapping resource are the files with extension hbm.xml

It is also possible to specify annotations for mapping. In such case Annotations will be provided in POJO(Plain Old java Objects) class. In this case, POJO Class name need to be specified as shown below.
<mapping class=”Employee”/>

In addition to above, property such as below are optional, and can be used on need basis
1. hbm2ddl.auto is to automatically create or update tables in database.
2. show_sql is to show SQL queries generated by Hibernate Framework.While debugging, if you want to check SQL queries, then this property need to be set to true.
Below is an example of Hibernate Configuration, XML file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
      <property name="hbm2ddl.auto">create</property> 
      <property name="show_sql">true</property><!-- can be used for debugging purpose -->
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/zzzz?zeroDateTimeBehavior=convertToNull</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">abcdfe</property>
    <mapping resource="empadd.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Also note that, it is possible to have different name for Hibernate Configuration file, in this case file name need to be specified in the Application(Java File), as shown below.
SessionFactory factory1 = new Configuration().configure(“hibernate.cfg.xml”).buildSessionFactory();

It is also possible to have multiple Hibernate Configuration files, in an Application.

You may also like to read:
What is Hibernate Mapping File?
Advantages of Hibernate?
What is XML file