Last Updated on September 2nd, 2020 at 11:50 am
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.
The important properties for Hibernate configuration file are given below:
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">
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.
Connection Pool Size
The connection pool size where a number of threads are available for connecting to the database whenever required.
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.
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.