Java – JDBC, Hibernate and JPA what’s the meaning and differences?

The purpose of this post is to show the meaning and what the difference between JDBC, JPA and Hibernate. This question is very common for those that start to study coding and causes a lot of confusion of concepts.

Table of Contents

JDBC

Let’s start with JDBC or Java Database Connectivity. When a programmer start to learn Java and makes his first code to access the database, probably he will read about JDBC rightway. JDBC is nothing more than an API (a set of classes and interfaces) of Java that we use for communication and transactions with the database.

Hibernate

Once the tasks for communication and transactions with the database in big projects start to be very painful, developers and companies have started to develop ORM frameworks. What is Framework? Well .. Roughly speaking, a framework is a set of classes and interfaces that will facilitate or expedite the performance of a given task on your system. So in this particular case, the Frameworks came to facilitate these activities with the database. And what is ORM? It is exactly what these types of frameworks does. Object-Relational Mapping. The object is your Java code that is object-oriented and relational is because we are working with a relational databases (MySQL, SQL Server, PostgreSQL, etc..).

The Hibernate is an ORM Framework, we would say the most popular for Java. EclipseLink is other example of ORM Framework for Java.

JPA

We have spoken what is JDBC and Hibernate. But what is JPA? JPA is the acronym for Java Persistence API. It’s simple. JPA is just a specification describing a common interface for all ORM frameworks.

If there wasn’t a specification, when you were using Hibernate would have to invoke a method name, and when you were using EclipseLink would have to use another method name to do the same thing. So the specification standardizes the interfaces between the frameworks. In practice, if you use JPA in your project, you may some day change to Hibernate from EclipseLink without need to change to much your code, because these two frameworks implements the JPA specification. So you make your code flexible to change the ORM Framework anytime, without much changes needed.

Leave a Reply

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