Setting up Environment for Hibernate

Introduction

In the previous tutorial, you have seen a brief introduction to the ORM tool named as  Hibernate. We have seen its importance, its purpose of uses, its advantages over JDBC, and comparison of both JDBC and Hibernate. It core purpose is to persist data. It is the more Elegant tool than others. In this tutorial, you will learn setting up the development environment for hibernate.

Collect required dependencies:

The first thing to do for setting up the environment and start using hibernate is to Download the binaries of hibernate which are present in the form of jar files. To download visit the following site (http://hibernate.org/orm/downloads/) and download the latest release. This download will give us the hibernate jars, and the jars on which hibernate depend on JPA, etc.

Getting started

Open up the Eclipse and create a project. Right-Click on the Project Explorer à Click “New” à got to “Others” this will open the selection wizard, in this selection wizard find “Java Project” under “Java” directory and click “Next”.

Selection Wizard for Project Selection
Selection Wizard for Project Selection

Write the name for project “HibernateProject” and click finish.

New Java Project Wizard asking for Project Name
New Java Project Wizard asking for Project Name

Select No for perspective

Open Associated Perspective Wizard asking for Perspective option
Open Associated Perspective Wizard asking for Perspective option

Include Hibernate Jars

Now we have to include the jar files for hibernate, to do this, right-click on the project and go to properties.

Right Click on project and got to Properties
Right Click on project and got to Properties

Then Click on Java Build Path -> select Libraries Tab -> click Add Libraries. The button on the right this will open up the new window -> select “User Library” from the list and Click “Next”

Java Build Path for Eclipse
Java Build Path for Eclipse

Now again in the new window click on the “User Library” button à then click on the “New” write a name for your Hibernate library let’s say “Hibernate” and click “OK”.

Add New Library in Eclipse
Add New Library in Eclipse

Now select the “Hibernate” that we have just created and click on “Add External Jars” and browse for hibernate jar folder that you have downloaded in the “Collect required dependencies” section discussed above. Add all the libraries included in lib/JPA and lib/required directories. Finally, click “OK”.

Add External Jars in the New Library of Eclipse
Add External Jars in the New Library of Eclipse

Select the Hibernate and Click Finish.

Select Hibernate from user libraries in Eclipse
Select Hibernate from user libraries in Eclipse

Then click “Ok”

Java Build path with Added Hibernate Jars
Java Bild path with Added Hibernate Jars

You have successfully added all the Jars in the project. Thus, the environment for Hibernate is all set.

All Hibernate Added Jars in Eclipse project
All Hibernate Added Jars in Eclipse project

Installing the Database

You can configure any installed database with the Hibernate. Hibernate internally uses JDBC to access the database. You can download the JDBC driver for your selected database. We will use JDBC driver for SQLite database. Download the jar and add this jar to the library.

Now we have to include the JDBC jar files for selected database, to do that right click on the project and go to properties.Then Click on Java Build Path -> select Libraries Tab -> click Add External Libraries then click the right button-> browse for the downloaded JDBC jar and add it.

1.11 Added JDBC Jar for Hibernate

Summary:

In this tutorial, we have accomplished following things.

  • Setting up the environment for Hibernate.
  • Configure a database for it.

Hope that you like this tutorial. Stay tuned for more upcoming tutorials. Stay Blessed!

About Author: Uzair Ahmed Khan is Technical Content Writer, Computer Software Blogger and Software Engineer Enthusiast with a keen eye on Java Technologies other Related Developments.