Important properties in hibernate configuration file

There are mainly six important tags or properties for hibernate configuration file. Hibernate configuration file naming convention is generally hibernate.cfg.xml and it is generally placed in the classpath.

This can also be configured in the hibernate.properties file. If both hibernate.cfg.xml and hibernate.properties are found in the classpath then hibernate.cfg.xml overrides the hibernate.properties file.

Even it is possible to remove completely XML or properties file and use annotation based configurations for Hibernate using Java.

Important Properties

The important properties for Hibernate configuration file are given below:

DTD

The is DTD and it is required for the data type definition.

<?xml versi encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

JDBC Configuration

The database connection settings are configured into the XML file.

<property name="connection.driver_class">db_driver(com.mysql.jdbc.Driver/com.mysql.cj.jdbc.Driver)</property>
<property name="connection.url">db_connection_url(jdbc:mysql://localhost:3306)/db_name</property>
<property name="connection.username">db_username</property>
<property name="connection.password">db_password</property>

SQL Variant Generation

The dialect which is required to generate your appropriate query or HSQL query. This dialect is dependent on the database and you need to choose according to your database.

<property name="dialect">db_dialect(org.hibernate.dialect.MySQLDialect)</property>

Connection Pool Size

The connection pool size where a number of threads are available for connecting to the database whenever required.

<property name="hibernate.connection.pool_size">10</property>

Auto-Generation of Schema

This property automatically drop the schema from the database if exists and create the schema in the database again on application startup.

<property name="hibernate.hbm2ddl.auto">create-drop</property>

Mapping Files

Mapping files are XML files which map the Java classes with the database tables.

<mapping resource="com/roytuts/domain/model/Department.hbm.xml"/>
<mapping resource="com/roytuts/domain/model/Employee.hbm.xml"/>

 
Thanks for reading.

Related posts

Leave a Comment