Hibernate

Hibernate Tutorial

Table of Contents

For simple database connectivity to applications from Java-based software, JDBC is used. And for object-relational mapping to the database from the software developed using Java technology, Hibernate is used. Hibernate is one of the high-performance Object /Relational persistence and query services where it will be licensed under an open-source GNU Lesser General Public Licence and also will be a free download. Hibernate will take care of the mapping from Java classes to database tables and gives data query and retrieval facilities.

Hibernate ORM review

JDBC

Its expansion stands for Java database connectivity. The relational database can be accessed by Java programs using the Java API set provided by JDBC. The Java APIs enable java programs to execute SQL statements and interact with any SQL compliant database. JDBC has a very easy architecture to write a database-independent application that will run on the different platforms and interact with the different DBMS without any modification.

What is ORM (object-relational mapping)?

In the object-oriented system always there is a mismatch between the object model and the relational database. RDBMS will show the data in the tabular format whereas object-oriented languages, like java or C#, will represent the interconnected graph of objects.

ORM is considered a programming technique for converting the data between relational databases and object-oriented programming languages like java etc.

The advantages of ORM are:

The business code will access the objects rather than DB tables.

It hides details of SQL queries from OO logic.

It will be based on the JDBC as under the Hood.

No need to deal with database implementation.

Entities depend on the business concepts apart from the database structure.

It has Transaction management and automatic key generation.

It is having fast development of the application.

Hibernate is an ORM solution for JAVA. Itā€™s an open-source persistent framework that is created by Gavin King in 2001. It is strong powerful, high-performance object-relational persistence and query service for Java applications.

Hibernate will map Java classes to database tables and also from java data types of the SQL data types and relieves the developer from 95% of common data persistence related programming tasks. Hibernate will sit between traditional java objects and a database server to handle all the works persisting in those objects based on the appropriate O/R mechanisms and patterns.

Advantages of Hibernate

Hibernate advantages are

  1. Hibernate will care about mapping the Java classes to the database tables by using XML files and without writing any line of code.
  2. The Java objects can be stored to and retrieved from the DB directly using simple APIs.
  3. If there will be a change in the database or any in the table then we need to change the XML file properties only.
  4. It always abstracts away the unfamiliar SQL types and provides a way to work all over the familiar Java objects.
  5. Hibernate will not be requiring an application of objects of our database.
  6. Minimises database access with smart fetching strategies.
  7. Provides simple querying data.

There are few database engines which will support Hibernate

  1. HSQL database engine
  2. DB2/NT
  3. MYSQL
  4. FrontBase
  5. Postgres
  6. Oracle

Hibernate Architecture

Hibernate will be a layered architecture that helps the user to operate without having known to underlying APIs. Hibernate makes sure that the use of database and configuration data to provide the persistence services to the application.

Hibernate uses many existing Java APIs, like JDBC, Java Transaction API and Java Naming and directory interface. JDBC provides a rudimentary level of abstraction of functionality common to relational databases, allowing almost any database with a JDBC driver supported by Hibernate will be integrated with the J2EE application servers.

Configuring the Object

Hibernate application creates the first object called a configuration object. It is usually created once during application initialisation. The configuration object file contains the properties required by Hibernate.

The configuration Object will provide two objects

  1. The database connection is handled through one or more configuration files that are supported by Hibernate. These files are hibernated .properties and hibernate.cfg.xml.
  2. Class mapping setup This component creates the connection between java classes and database tables.

Questions

  1. Why hibernate is an ORM solution for Java?
  2. Explain the architecture of hibernating?

2 Responses

  1. 1.Why hibernate is an ORM solution for Java?
    It is strong powerful, high-performance object-relational persistence and query service for Java applications.
    2.Explain the architecture of hibernating?
    Hibernate has a layered architecture which helps the user to operate without having to know the underlying APIs. Hibernate makes use of the database and configuration data to provide persistence services (and persistent objects) to the application.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share this article
Subscribe
By pressing the Subscribe button, you confirm that you have read our Privacy Policy.
Need a Free Demo Class?
Join H2K Infosys IT Online Training
Enroll Free demo class