Tuesday, February 6, 2007

Hibernate Configuration File

Table of Content

  1. Introduction
  2. Configuration with hibernate.properties
  3. Configuration with hibernate.cfg.xml


In order to configure the Hibernate frameworks, a programmer must create a properties file. This file must be included in the class-path of the program which is using Hibernate. The best method to accomplish this is to place this file inside the application jar file. There are two available types of properties file for Hibernate. Both have the same functionality, however their formats are different.

Configuration with hibernate.properties

This file can be copied from a Hibernate distribution, and modified as required. Most of the of the settings in this file do not need to be modified. A programmer should modify the database dialect, database connection, user name, and password. For instance, the following would connect to an Oracle database on the machine executing the program.
... hibernate.dialect org.hibernate.dialect.OracleDialect hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver hibernate.connection.username aUserName hibernate.connection.password aPassword hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl ...

Configuration with hibernate.cfg.xml

This file can be copied from a Hibernate distribution, and modified as required. This method is a more career enhancing method to configurate the Hibernate framework since you can claim to your boss that you are using xml technologies. Unfortunately, this is the only difference between the two methods, so choose the one that suits your mood. The following xml document configures Hibernate to connect to the same database as the one given in the properties example.

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"






No comments: