Hibernate Configuration File

shape Description

Hibernate Configuration File is the backbone to hibernate application and it consists of tags to establish the connection to the database server. Hibernate Configuration file doesn’t support Annotations, Configuration file creates only XML file. Hibernate Configuration file is extended to Xxx.cfg.xml. If developer use more databases, then more configuration files are needed. Following are the connections will be given in the XML file.

shape Syntax

<hibernate-configuration>
<session-factory></span></span><!-- Related to the connection START -->
<property name="connection.driver_class">Driver Class Name </property>
<property name="connection.url">URL </property>
<property name="connection.user">user </property>
<property name="connection.password">password</property>
<!-- Related to the connection END --><!-- Related to hibernate properties START -->
<property name="show_sql">true/false</property>
<property name="dialet">Database dialet class</property>
<property name="hbm2ddl.auto">create/update or what ever</property>
<!-- Related to hibernate properties END-->

<!-- Related to mapping START-->
<mapping resource="hbm file 1 name .xml" / >
<mapping resource="hbm file 2 name .xml" / >
<!-- Related to the mapping END -->

</session-factory>
</hibernate-configuration>
Properties Description
hibernate.connection.driver_class The JDBC driver class.
hibernate.dialect This property makes Hibernate generate the suitable SQL for the picked database.
hibernate.connection.url The JDBC URL to the database instance.
hibernate.connection.username The database username.
hibernate.connection.password The database password.
hibernate.connection.pool_size Limits the number of connections waiting in the Hibernate database connection pool.
hibernate.connection.autocommit Allows autocommit mode to be used for the JDBC connection.

The configuration file will consist of connection properties, hibernate properties, mapping file name will consist of all the related class names. Dialect classes are used to convert HQL statements to database specific statements. To connect any database with hibernate, We need to specify the database Dialect class in hibernate. cfg. xml. If a show_sql value is true, generated the SQL statements in a console.

Summary

shape Key Points

  • Configuration file does not have annotations.
  • In two ways configuration file can be written as XML and by property file.
  • Before XML file developers used to write hibernate configuration file in property file.