top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

    Get Free Article Updates

Facebook Login
Site Registration
Print Preview

Setting up Hibernate in Eclipse IDE

+2 votes

Hibernate is based on the Java technologies and it is used in the Java applications for developing the data access layer for the application.

Steps to create Hibernate based applications

Step 1: Create database and tables

Step 2: Create POJO class

Step 3: Create mapping meta-data

Step 4: CRUD operations


Configuring the Hibernate environment

I am using Eclipse IDE to perform configuration of Hibernate environment. Install Eclipse and add required JDK version of Java. Create a Java Project in Eclipse and follow the steps below:-


Add required Jar files to Java Project

Downloading the latest version of Hibernate, It includes the libraries necessary to run the Hibernate based applications.

Java Build Path

Note: Please download only the required version of hibernate jar file from official website at

Installing Hibernate is very easy process, you just have to unzip and then copy the library files from its lib directory. If you are using Eclipse, you have to copy the files into lib directory of your project. After coping the file in your project's lib directory, add the lib files in the class build path as shown in above figure.

For copying the file into build path:

Right click on the project > Java Build Path > select "Libraries" > Add JARs > then select the jar files from your project, this will make the jar files available in your project.


Hibernate Configuration files

The Hibernate framework uses the hibernate.cfg.xml and other optional files for configuring the ORM runtime. The things you will have to change is the dialect, database url, database username and database password.

Here are the important properties of the file:

hibernate.connection.driver_class - The JDBC Driver class

hibernate.connection.url - Database URL

hibernate.connection.username - Database user name

hibernate.connection.password - Password to connect to database

hibernate.connection.pool_size - Default connection pool size

show_sql - If it is true it will show all the sql generated by Hibernate

dialect - Database dialect

Setup the MySQL database

I have used MySQL Database for developing the tutorial. MySQL is free database which works well with the Hibernate framework. We can use other database by changing few settings in the xml file and connect to the supported database.

Download the MySQL database and then setup of your computer. After installing MySQL database you should create database and table in the database. Add database driver into your Java Project. See in figure 1: I have added ojdbc6.jar file in my Java Project.

Note: remember the user name, password and port number of MySQL database.

Create a POJO class

Add the following code in package “com.user.bean”

Create connect class to connect your database in package “com.user.utill”

Write the code for Main class in package “com.user.main”

After executing the Main class you will get successful Insertion

You can use the Hibernate to perform operations like select, insert, update and delete the records in the table. Hibernate automatically generates the SQL query automatically to perform these operations against database.

posted 6 days ago by Atindra Kumar Nath

  Promote This Article
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Contact Us
+91 9880187415
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.