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.
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”.
Write the name for project “HibernateProject” and click finish.
Select No for perspective
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.
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”
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”.
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”.
Select the Hibernate and Click Finish.
Then click “Ok”
You have successfully added all the Jars in the project. Thus, the environment for Hibernate is all set.
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.
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.