Environment Set up for Hibernate

In the previous article, we have seen The Introduction of Hibernate you can check it here What is Hibernate?. In this article, we will cover how to set up an environment for Hibernate development.

A Development Environment in software and web application is a workplace where changes from the developer are deployed, test before reaching a live web site. In this tutorial, we will see How to set up a Development Environment for  Hibernate development.

How to set up the Hibernate Environment?

For a beginner, I am going to tell you about How to set up the environment. Following are the tools you will need:

  • JDK(Java Development Kit)
  • Java Application Server
  • IDE for Java
  • MYSQL database
  • Download Hibernate Framework libraries.

JDK(Java Development Kit)

JDK is a development environment for building applications using Java Programming language. It includes tools useful for developing and testing programs.

Download JDK https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html.

After Downloading JDK, it will ask you to install JRE(Java Runtime Environment) to install it. Now You have to set up some Environment variables in your OS.

  • Go to My Computer, Right Click on it. Click Properties.
  • Click on Advanced System Setting
  • Click on Environment Variable.
  • In The System Variable, Click on Path and edit it.
  • Add the java installation path to the path variable like “C:\Program Files\jdk1.8.0_20\bin” (it should be a double quote)
  • Click OK and Ok.
  • Just restart your PC
  • Now Open cmd prompt and type “Java version” (for checking whether it is installed)
  • It will return the Java Version else you need to follow these steps again.

Java Application Server

In order for web applications to run, we will need a Web Server. There are different web servers available. For now, we will use the popular Apache Tomcat Server.

  • Get the Apache Server from https://tomcat.apache.org/download-90.cgi and Download it.
  • Unzip the file into some Location.
  • Now click on the Setup, Click next on the setup.
  • Then, Click I agree with the license agreement.
  • Check the Component button and click Next.
  • Enter username and password(make it easy so that you can remember it) and click Next.
  • Now see whether the path for the JRE is right and then click Next.
  • Click Install and wait till the installation completes.
  • At last, Click the Finish button. (You can uncheck both the options here which are Read me files and Run apache)

Let us verify its installation.

  • Open the browser
  • Type in http://localhost:8080
  • If you are able to see the apache tomcat page then the installation is successful.

IDE Installation

IDE is an Integrated Development Environment in which java programs are going to be executed. There are many IDE’s available like IntelliJ IDEA, NetBeans, Eclipse, etc. which are open source. Here we are going to use Eclipse. You can get Eclipse from http://www.eclipse.org.

  • Download as per your OS(32 bit or 64 bit).
  • Unzip the file into some location after downloading it.
  • Go to that folder and double click on eclipse.exe.
  • Now Eclipse will prompt and ask you the workspace folder(Where all your files will be saved ).
  • It will take time and Eclipse will start.

How to Connect Eclipse IDE with Apache Server?

  • Open Eclipse, there is a server tab at the bottom.
  • Click on the link to create a server.
  • Select the right server from the options given(for now Apache Tomcat).
  • Click Next and give the installation path for tomcat (navigate the location till tomcat ) where it is installed.
  • Click Finish.
  • Now you are able to see the server name Just right click on it. You can now start it, stop it, delete it as per your choice.

What is the Error Faced by Users?

When you start a server, it is most probable you will face the following error:” starting Tomcat v(any) Server at localhost has encountered a problem”.

  • Just double click on the link below the server tab at the bottom.
  • Now one tab will open, just check the Ports tab and change the port number of HTTP/1.1 to any(I have used 8088).
  • Now, click save or do Ctrl+S.
  • Now, Once again right-click on the link of the server and start it. It will get started.

Download MYSQL Database

Mysql is a free, open-source RDBMS(Relational Database Management System). MYSQL is one of the best RDBMS being used for developing various web-based software applications. We will look at the steps to install MYSQL in Windows OS.

Download the MySQL database from https://dev.mysql.com/downloads/mysql/ After Downloading the MYSQL community version, double click the installer file. Now the Installer window will be launched. Now, Follow the below steps.

  • Select the Full radio button to install MYSQL. Click on Next.
  • Click on Execute. It will take time to install the package (have patience here)
  • Click on Next. again Click on Next.
  • Now, you will see Type and Networking Page. Click Next.
  • Here it will ask you to write username and password which is important so make sure you keep it simple as it will be good to remember (I will suggest you keep both username and password as root). Click on Next.
  • Now, on the Windows Service page check the above two options of Configure MySQL server and start the
  • MYSQL and then select the Standart system Account radio button and click Next.
  • Now, When the configuration will be finished Click Finish to continue.

How to download Hibernate Framework libraries?

  • There are several Hibernate libraries available over the internet.
  • Download the latest version of Hibernate Framework libraries from http://www.hibernate.org/downloads.
  • Unzip it and save it to the directory. it will look like this

How to add Hibernate Library to the project?

  • Create a simple Java Project and add a lib directory inside the project name.
  • Copy the above all jar files inside the lib directory along with the MySQL connector jar files. (which is present in C:\Program Files (x86)\MySQL\Connector J 8.0\mysql-connector-java-8.0.21).
  • Right-click on project name>Build path> Configure Build Path

  • Click on Add JARs… then select your project and then select all jar files and click OK and then click apply.

Thus, I have just shown you how to add libraries to the project and environment set up for Hibernate development.

In the next article of this tutorial, we will cover the Configuration in Hibernate.