1. INTRODUCTION
Hibernate is an open source Object Relational Mapping (ORM) tool. It allows us to persist Plain Old Java Objects (POJO) to the database. The POJO refers to normal Java objects that do not do any special function nor implement any special interfaces of any of the Java frameworks such as EJB, JDBC, DAO, JDO, etc. Although hibernate internally uses JDBC API to interact with the database, it simplifies the development of Java application to interact with the database. The following are some of the advantages of using hibernate:
- It is an open source framework under the LGPL licence and hence may be freely downloaded.
- Hibernate allows us to use database independent queries written in Hibernate Query Language (HQL). So, changing the underlying database is simply a matter of modifying very few lines of code.
- Hibernate internally uses several levels of caching. Hence, the performance of hibernate framework is unquestionable.
- This framework also provides the facilities to create database tables automatically. So, programmers need not know SQL syntax.
- It also supports caching queries and provides statistics about query and database status.
2. INSTALLING HIBERNATE
We assume that the latest version of Java is already installed on your computer. Download .zip (for windows) or .tgz (for Unix) from http://hibernate.org/orm/downioads. We downloaded the file hibernate-reiease-4.3.i.Finai.zip and when unzipped, a set of files was generated. A sample screen shot is shown in Figure 23.1:
The lib directory contains a set of folders containing Hibernate library. The primary JAR files to use hibernate API are stored in lib/required folder. Modify your classpath environment variable to point these JAR files or specify them using -cp option of Java and javac command. If you are using an IDE such as Eclipse, place them in your project library directory.
3. BASIC STEPS
A typical hibernate application is developed using the following steps:
- Writing a POGO class
- Creating a database table
- Creating configuration and mapping files
- Write code to save, retrieve, update, delete objects
Source: Uttam Kumar Roy (2015), Advanced Java programming, Oxford University Press.