Hibernate Tutorials : Setting up the environment for Hibernate

Setting up the Environment for Hibernate

For practicing Hibernate with some examples, we need to first setup our local environment. Hibernate don’t need any application server in order to perform transaction.

Step 1 : Understand Required Jars

First thing, we will need the required jar of Hibernate framework. It is not necessary to include all of the jars just to run a simple example. Following is the list of jars for simple hibernate example.

hibernate-core :  Hibernate core is the basic building block of the Hibernate framework which is required to run the application.

mysql-connector-java : Since we are connecting with MySql database then we need connector which helps to communicate with database server.

commons-dbcp : Commons DBCP is required jar if you want to add connection pooling functionality.

Step 2 : Setup Maven in your location system

Maven is dependency management tool so you don’t need to manually add the required libraries. Maven takes the responsibility and manage all dependencies automatically. Install and configure Maven on your system, found this link helpful Configure Maven.

Step 3 : Create Maven web app project

You can also create simple maven project, you don’t need to create web application project. But we are creating web app project for further examples. Please follow these steps to create maven project.

Go to File -> New -> Maven Project

Then click Next button

Select maven-archetype-webapp as below

Provide details for group id, artifact id and package and click on finish button to finish the setup.


That’s it, Maven project is created.

Step 4 : Configure dependencies in pom.xml

Maven uses pom.xml configuration file to manage dependencies. You can provide dependency details in pom.xml as below.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <name>HibernateTest Maven Webapp</name>


 <!-- database pool -->

 <!-- Hibernate ORM -->

 <!-- MySql Driver -->

 <!-- logging, slf4j -->


Now you are ready to run examples on hibernate.

Leave a Reply

Your email address will not be published. Required fields are marked *