Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Hibernate Hibernate4 Hibernate Configuration File

Related Tutorials


 
 

Share on Google+Share on Google+

Hibernate Configuration File

Advertisement
In this tutorial you will learn about the hibernate configuration file.

Hibernate Configuration File

In this tutorial you will learn about the hibernate configuration file.

To define a Hibernate Configuration info a resource file named hibernate.cfg.xml is used. Using this configuration file various of information is provided to the Hibernate such as :

  • onnection.driver_classc : This property element is used to provide the name of the driver class.
  • connection.url : This property element is used to provide the url for the database connection.
  • connection.username : This property element is used to provide the username by which you are logging to the database.
  • connection.password : This property element is used to provide the password by which you are logging to the databse.
  • connection.pool_size : This property element configures the number of connections of connection pool of the built-in Hibernate.
  • dialect : This property defines the particular SQL variant with which the Hibernate will carry on a conversation. Use of this property is necessary when there are multiple databases are targeted by an application.

At last of you will be required to map the persistent class(POJO) file to the configuration.

Example :

Here I am giving an example of how to write a configuration file. A configuration file hibernate.cfg.xml may be written as :

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

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://192.168.10.13:3306/data
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<mapping class="/roseindia/Employee" />

</session-factory>
</hibernate-configuration>
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: February 16, 2012

Related Tutorials

Discuss: Hibernate Configuration File  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com