Introduction to hibernate framework

Target Audience

This tutorial is designed for Java programmers who need to understand the Hibernate framework and its application.

Prerequisites:

Before proceeding with this tutorial you should have a good understanding of the Java programming language and also good understanding of SQL.
This is 1 of 8 parts of tutorial series

Tutorial Content:

Before understanding hibernate framework,we need to understand Object Relational Mapping(ORM).

What is ORM?

ORM is a programming method to map the objects in java with the relational entities in the database.In this,entities/classes refers to table in database,instance of classes refers to rows and attributes of instances of classes refers to column of table in database.This provides solutions to the problems arise while developing persistence applications using traditional JDBC method. This also reduces the code that needs to be written.

Need for tools like hibernate:

The main advantage of ORM like hibernate is that it shields developers from messy SQL. Apart from this, ORM provides following benefits:
Improved productivity:
  • High-level object-oriented API
  • Less Java code to write
  • No SQL to write
Improved performance:
  • Sophisticated caching
  • Lazy loading
  • Eager loading
Improved maintainability:
  • A lot less code to write
Improved portability:
  • ORM framework generates database-specific SQL for you

What is hibernate?

Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables.The main goal of hibernate is to relieve the developer from the common data persistence related tasks.It maps the objects in the java with the tables in the database very efficiently and also you can get maximum using its data query and retrieval facilities.Mainly by using Hibernate in your projects you can save incredible time and effort.

Architecture of hibernate :

Following is a detailed view of the Hibernate Application Architecture with few important core classes.
The Hibernate architecture is layered to keep you isolated from having to know the underlying APIs.Hibernate is like a bridge between java application and relational database.

Core classes of hibernate are:

Session Interface:

This is the primary interface used by hibernate applications. The instances of this interface are lightweight and are inexpensive to create and destroy. Hibernate sessions are not thread safe.It allows you to create query objects to retrieve persistent objects.It wraps JDBC connection Factory for Transaction.It holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier .
SessionFactory Interface :

This is a factory that delivers the session objects to hibernate application.It is a heavy weighted object so generally there will be a single SessionFactory for the whole application and it will be shared among all the application threads.The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work.

SessionFactory object is created with the help of configuration object.

Configuration Interface :

This is used to configure hibernate. It’s also used to bootstrap hibernate. Mapping documents of hibernate are located using this interface.

Transaction Interface :

This is an optional interface but the above three interfaces are mandatory in each and every application. This interface abstracts the code from any kind of transaction implementations such as JDBC transaction, JTA transaction.

Query and Criteria Interface :

This interface allows the user to perform queries and also control the flow of the query execution.

Related Posts

  • Get current year in java
    13 July

    Get current year in Java

    Table of ContentsUsing Date and SimpleDateFormatUsing CalendarUsing LocalDateUsing LocalDateTimeusing ZonedDateTimeUsing OffsetDateTimeUsing Instant and ZoneIdUsing Instant and ZoneOffsetConclusion In this post, we will see how to get current year in Java. Using Date and SimpleDateFormat The Date class was introduced in Java 1.0 and provided different approaches to work with time. The SimpleDateFormat inherits from DateFormat […]

  • 13 July

    Remove substring from String in Java

    Table of ContentsUsing String’s replace method to remove substring from String in JavaUsing String’s replaceFirst method to remove substring from String in JavaUsing String’s replaceAll method to remove substring from String in JavaUsing StringBuilder’s delete() method to remove substring from String in JavaUsing StringBuilder’s replace() method to remove substring from String in JavaConclusion In this […]

  • 9Cartoon
    13 July

    13 Best Working 9Cartoon Alternatives in 2021 (Tried and Tested)

    Table of ContentsBest 9cartoon AlternativesCartoonsOnAnimeDaoAnimeToonKissAnimeToonGetWatch Cartoons OnlineCartoonCrazyToonovaKimCartoonWatch SeriesNyaaToonJetKissCartoonFrequently Asked QuestionsWhat is 9cartoon?Is 9cartoon free?What happened to 9cartoon?Which are the best 9cartoon alternatives?Wrapping Up Are you having trouble accessing 9cartoon? Well then, you’re just at the right place. 9cartoon is a well-known web-based platform that bagged a large quality of cartoons, relative TV shows and movies. […]

  • 13 July

    Einthusan Alternatives : 16 Best websites like Enthusan in 2021

    Table of ContentsEinthusan alternativesYouTubeYuppTVSonyLIVJio CinemaHotstarVootZee5HungamaAmazon Prime VideoAirtel XtremeMX PlayerEros NowNetflixHonorable Mentions123 MoviesF MoviesSoap2dayFrequently Asked Questions**Is Einthusan Blocked in India?Is Einthusan Safe?Is Einthusan Free?Einthusan Downloader: Is it legit?Final Words Einthusan is a well-known platform for watching movies online. From streaming in different languages to downloading them for online viewing, the platform offered everything that movie lovers […]

  • CQATest
    13 July

    Everything You Need to Know About CQATest in 2021

    Table of ContentsCQATest: A Brief OverviewHow Can CQATest Help?Problems Associated with CQA TestFixing Problems Associated with CQATestDisabling CQATest AppMethod 1: Force Stopping CQATest AppMethod 2: Resetting Your DevicePrecautions: Things to Keep in Mind Before Disabling CQATest.FAQsWhat is CQATest on Android?What does CQA stand for?Is CQATest app a virus?Is CQA Test Safe?What are the most common […]

  • Copy DataFrame in Python
    10 July

    Copy DataFrame in Pandas

    This articles provide different ways to copy DataFrame in Pandas.

Comments

  1. Is it possible to create object of Configuration interface?
    plz chk above code ..
    Configuration configuration=new Configuration();

  2. Is Configuration class or interface?
    If you say yes, can we create object for java interface.
    Plz explain me.

  3. Hello Sir,I am a Sachin and beginer in java.I followed your tutorials properly to learn hibernate and they work well.But when i created HibernateMain.java file.This file shows errors.The Following import can not be resolved.

    import org.hibernate.service.ServiceRegistry;
    import org.hibernate.service.ServiceRegistryBuilder;

    Sir please tell me where i made a mistake.what is the solution for this.

  4. Hibernate is open source light weight ORM (Object Relational Mapping) tool
    It is a powerful, ultra –high performance object/relational persistence and query service for Java
    It simplifies the development of java application to interact with database.
    It lets us develop persistent objects following common Java idioms – including association, inheritance, polymorphism, composition and the Java collections framework
    It internally uses the JDBC API to interact with the database.
    Hibernate Query language is designed as a “minimal” object oriented extension to SQL, provide an elegant bridge between the object and relational worlds.

Leave a Reply

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

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.