A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Hibernate Environment Setup

Hibernate Environment Setup

This chapter will explain how to install Hibernate and other associated packages to prepare a develop environment for the Hibernate applications. We will work with Oracle database to experiment with Hibernate examples, so make sure you already have setup for Oracle database. 

Downloading Hibernate: 

It is assumed that you already have latest version of Java is installed on your machine. Following are the simple steps to download and install Hibernate on your machine.
  • Make a choice whether you want to install Hibernate on Windows, or Unix and then proceed to the next step to download .zip file for windows and .tz file for Unix.
  • Download the latest version of Hibernate from http://www.hibernate.org/downloads.
  • At the time of writing this tutorial I downloaded hibernate-distribution-3.6.4.Final and when you unzip the downloaded file it will give you directory structure as follows.
Installing Hibernate:

Once you downloaded and unzipped the latest version of the Hibernate Installation file, you need to perform following two simple steps. Make sure you are setting your CLASSPATH variable properly otherwise you will face problem while compiling your application.
  • Now copy all the library files from /lib into your CLASSPATH, and change your classpath variable to include all the JARs:
Finally, copy hibernate3.jar file into your CLASSPATH. This file lies in the root directory of the installation and is the primary JAR that Hibernate needs to do its work.

Hibernate Prerequisites:

Following is the list of the packages/libraries required by Hibernate and you should install them before starting with Hibernate. To install these packages you would have to copy library files from /lib into your CLASSPATH, and change your CLASSPATH variable accordingly.

dom4j - XML parsing www.dom4j.org/
Xalan - XSLT Processor http://xml.apache.org/xalan-j/
Xerces - The Xerces Java Parser http://xml.apache.org/xerces-j/
cglib - Appropriate changes to Java classes at runtime http://cglib.sourceforge.net/
log4j - Logging Faremwork http://logging.apache.org/log4j
Commons - Logging, Email etc. http://jakarta.apache.org/commons
SLF4J - Logging Facade for Java http://www.slf4j.org

Hibernate Configuration
Hibernate requires to know in advance where to find the mapping information that defines how your Java classes relate to the database tables. Hibernate also requires a set of configuration settings related to database and other related parameters. All such information is usually supplied as a standard Java properties file called hibernate.properties, or as an XML file named hibernate.cfg.xml.
I will consider XML formatted file hibernate.cfg.xml to specify required Hibernate properties in my examples. Most of the properties take their default values and it is not required to specify them in the property file unless it is really required. This file is kept in the root directory of your application's classpath.