In our previous tutorial we got introduced to what hibernate is, and its advantage and disadvantage. In this tutorial you will learn how to install Hibernate and other associated packages to setup an environment for the Hibernate applications.
Hibernate Framework is available for downloading straight from its official site. The latest version of this framework for this day is 4.3.8
Simply go to http://hibernate.org/orm/downloads/.
Choose Stable-4.3.8 final Download option as shown on the picture below:
Once downloaded Unzip the archive files.
Now Create a new Java Project(File -> New -> Java Project) and enter Hibernate4HelloWorld as project name. Create lib sub directory in this project.
Copy all 10 jar files Under lib/required directory of the hibernate distribution that you have downloaded to the lib directory of the “Hibernate4HelloWorld” project.
Those 10 jars are
These are the main jar files to run hibernate related programming,
Additionally, you will need the database driver JAR that Hibernate uses to connect to your database. I use Oracle Express Edition(Oracle XE) and it’s database driver jar is here on Windows:
Copy this ojdbc14.jar to the lib directory of the “Hibernate4HelloWorld” project.
Note: if you have another database management system already installed, then you should replace this database driver JAR with a different database driver JAR. For example, you must download MySQL Connector/J (official JDBC driver for MySQL) from http://www.mysql.com/downloads/connector/j/ if your database is MySQL.
Now I will create a User library on Eclipse IDE. Then, I will add all JAR files in the Hibernate4HelloWorld\lib directory to this User library and add this User library to the project build path.
Click Project–>Properties on the top menu bar of Eclipse.
Click Java Build Path–>Add Libraries.
Then, select “User Library” and click Next button.
Then click on User Library button
Now in the below screen click New button then enter “Hibernate” as the User library name.
Select “Hibernate” User library that we just created and click Add External JARS… button.
Select all JAR files in the lib folder of the “Hibernate4HelloWorld” project and click Open button to add all JAR files to “Hibernate” User library. Now “Hibernate” User library is ready and now click on ok.
Finally, select “Hibernate” User library and click Finish button.
After adding “Hibernate” User library to “Hibernate4HelloWorld” project, it will look like this:
In our next article we will learn about Simple Hibernate Application Requirements using Annotation as well as XML Mapping