Pages Navigation Menu

Coding is much easier than you think

Hibernate Installation/Setup on Eclipse IDE

 

 
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.
 

Environment Used

  • JDK 7 (Java SE 7)
  • Eclipse JUNO IDE
  • Hibernate jars
  • Any RDMS Database(Oracle 10 g in this example)

 

Setting up development environment

 
To install Eclipse IDE read this page
 

Downloading Hibernate

 
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
 

antlr-2.7.7.jar
dom4j-1.6.1.jar
hibernate-commons-annotations-4.0.5.Final.jar
hibernate-core-4.3.8.Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
jandex-1.1.0.Final.jar
javassist-3.18.1-GA.jar
jboss-logging-3.1.3.GA.jar
jboss-logging-annotations-1.2.0.Beta1.jar
jboss-transaction-api_1.2_spec-1.0.0.Final.jar

 
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:
C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar
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

2 Comments

  1. How to retrieve the data from mysql db???