What is Hibernate Configuration file?

Hibernate Configuration :-

  • It is an XML file where we descibe database connection details (username, password, url, driver class name).
  • There we are declare Hibernate Properties like dialect, show_sql, second-level-cache ,hbm2ddl.auto.. etc
  • Hibernate uses this file to establish connection to the particular database server.
  • For each database we must create one hibernate configuration file.
  • Suppose if we want to connect two databases, like Oracle and MySql, then we must create 2 configuration files.
  • We can execute hibernate.cfg.xml from following way :-

             Configuration cfg=new Configuration();   cfg.configure(“hibernate.cfg.xml“);

					<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"


		<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
		<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
		<property name="connection.username">system</property>
		<property name="connection.password">oracle</property>
		<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
		<property name="hbm2ddl.auto">update</property>
		<property name="show_sql">true</property>
		<property name="hibernate.cache.use_second_level_cache">true</property>
		<!-- XML type Mapping files entries -->
		<mapping resource="com\employee.hbm.xml" />
		<!-- annotation type files data entries -->
		<mapping class="com.Customers" />

Here we are declare table and column in XML type which is describe inside employee.hbm.xml file this will be call from mapping resource inside Hibernate.cfg.xml.

We are declare table and column in an entity class from annotation base.it will be call from mapping class inside Hibernate.cfg.xml.