Hibernate configuration file

As we discussed that hibernate works as an intermediate layer between java application and relational database. So hibernate needs some configuration setting related to the database and other parameters like mapping files. A hibernate configuration file contains all such information.

A hibernate configuration file mainly contains three types of information:

  1. 1. Connection Properties related to the database.
  2. 2. Hibernate Properties related to hibernate behaviour.
  3. 3. Mapping files entries related to the mapping of a POJO class and a database table.

How to create a hibernate configuration file?

We can create a hibernate configuration file either by using java properties file known as hibernate.properties or by using an xml file known as hibernate.cfg.xml. The hibernate.cfg.xml file is used mostly.
Note: No. of hibernate configuration files in an application is dependence upon the no. of database uses. No. of hibernate configuration files are equals to the no. of database uses.


// Connection Properties
<property name="connection.driver_class">driverClassName</property>
<property name="connection.url">jdbcConnectionURL</property>
<property name="connection.user">databaseUsername</property>
<property name="connection.password">databasePassword</property>
// Hibernate Properties
<property name="show_sql">true/false</property>
<property name="dialet">databaseDialetClass</property>
<property name="hbm2ddl.auto">like create/update</property>
// Mapping files entries
<mapping resource="mappingFile1.xml" />
<mapping resource="mappingFile2.xml" />

No comments: