Hibernate Configuration - Hibernate

What is Hibernate Configuration?

Hibernate requires to know in proceed where to find the mapping information that defines how your Java classes communicate to the database tables. Hibernate also requires a set of formation settings connected to database and other correlated parameters. All such information is usually supplied as standard Java properties file called hibernate. Properties, or as an XML file named hibernate.cfg.xml.

I will consider XML formatted file hibernate.cfg.xml to identify required Hibernate properties in my example. Most of the properties take their defaulting values and it is not required to detail them in the property file unless it is really required. This file is kept in the root directory of your application's class path.

Hibernate Properties:

Following is the list of important properties you would require to configure for databases in a individual situation:

S.N. Properties and Description
1 hibernate.dialect
This property makes Hibernate generate the appropriate SQL for the chosen database.
2 hibernate.connection.driver_class
The JDBC driver class.
3 hibernate.connection.url
The JDBC URL to the database instance.
4 hibernate.connection.username
The database username.
5 hibernate.connection.password
The database password.
6 hibernate.connection.pool_size
Limits the number of connections waiting in the Hibernate database connection pool.
7 hibernate.connection.autocommit
Allows autocommit mode to be used for the JDBC connection.

If you are using a database along with an application server and JNDI then you would have to configure the following properties:

S.N. Properties and Description
1 hibernate.connection.datasource
The JNDI name defined in the application server context you are using for the application.
2 hibernate.jndi.class
The InitialContext class for JNDI.
3 hibernate.jndi.<JNDIpropertyname>
Passes any JNDI property you like to the JNDIInitialContext.
4 hibernate.jndi.url
Provides the URL for JNDI.
5 hibernate.connection.username
The database username.
6 hibernate.connection.password
The database password.

Hibernate with Myself Database:

I am one of the generally accepted open-source database systems accessible today. Let us form hibernate.cfg.xml configuration file and place it in the root of your application's class path. You would have to make sure that you have tested database available in your me database and you have a user test available to access the database.

The XML configuration file necessity conforms to the Hibernate 3 Configuration DTD, which is presented from http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd.

The beyond configuration file includes <mapping> tags which are associated to hibernate-mapping file and we will observe in next chapter what exactly is a hibernate mapping file and how and why do we use it. Following is the list of different main databases language property type:

Database Dialect Property
DB2 org.hibernate.dialect.DB2Dialect
HSQLDB org.hibernate.dialect.HSQLDialect
HypersonicSQL org.hibernate.dialect.HSQLDialect
Informix org.hibernate.dialect.InformixDialect
Ingres org.hibernate.dialect.IngresDialect
Interbase org.hibernate.dialect.InterbaseDialect
Microsoft SQL Server 2000 org.hibernate.dialect.SQLServerDialect
Microsoft SQL Server 2005 org.hibernate.dialect.SQLServer2005Dialect
Microsoft SQL Server 2008 org.hibernate.dialect.SQLServer2008Dialect
MySQL org.hibernate.dialect.MySQLDialect
Oracle (any version) org.hibernate.dialect.OracleDialect
Oracle 11g org.hibernate.dialect.Oracle10gDialect
Oracle 10g org.hibernate.dialect.Oracle10gDialect
Oracle 9i org.hibernate.dialect.Oracle9iDialect
PostgreSQL org.hibernate.dialect.PostgreSQLDialect
Progress org.hibernate.dialect.ProgressDialect
SAP DB org.hibernate.dialect.SAPDBDialect
Sybase org.hibernate.dialect.SybaseDialect
Sybase Anywhere org.hibernate.dialect.SybaseAnywhereDialect

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Hibernate Topics