JPA vs Hibernate

In this post, we will see JPA vs Hibernate.

For beginners, it might be confusing what is JPA, what it does and how it is different from Hibernate. Can we use JPA without hibernate? We are going to see these points in details.

Java Persistent API(JPA) is a specification or set of rules. It provides specifications for persisting and managing the data. The release date of the JPA 1.0 specification was 11 May 2006. So JPA is just specification. Hibernate is the implementation of these specifications.

JPA can’t do anything alone. It must be used either with Hibernate or EclipseLink or TopLink.

The most popular combination is JPA+Hibernate. So for question –  Can we use JPA without hibernate? The answer is no. We can’t use JPA alone.

Note – We can’t use JPA without Hibernate, EclipseLink or any other framework. Just for better understanding see below code snippet.

 

public interface Jpa {
void m1();
}

class Hibenate {
public void m1() {
// some implementation logic
}
}

class TopLink {
public void m1() {
// some implementation logic
}
}

class EclipseLink {
public void m1() {
// some implementation logic
}
}

Let’s see some API defined in JPA(javax.persitent package).

@Entity
@Coulmn
@CollectionTable
@Column
@ColumnResult
@ConstraintMode
@ConstructorResult
@Convert
@Converter
@Converts
@DiscriminatorColumn
@DiscriminatorValue
@ElementCollection
@Embeddable
@Embedded
@EmbeddedId
@EntityExistsException
@EntityGraph
@EntityListeners
@EntityManager
@EntityManagerFactory

 

Hibernate.

  • Hibernate is a framework which is used to communicate the java application to the database.
  • Hibernate is an ORM tool. ORM stands for Object Relational Mapping which maps the object(entity) to data stored in the database.
  • Hibernate introduced in 2001 by Gavin King.  See more details about Hibernate history and release here.
  • See more about Hibernate and ORM here.

 

That’s all about JPA vs Hibernate.

You may like.

Other Spring Data JPA and Hibernate tutorials.

Spring JPA docs.

Summary – We have seen JPA vs Hibernate.

  1. Java Persistent API (JPA) is an only specification which provides different API which further can be used with
    • Hibernate
    • TopLink
    • JDO
    • Eclipselink
  2. We can consider JPA as an interface whereas hibernate is the implementation of those interfaces.
  3. The initial release date of the JPA 1.0 specification is May 2006 whereas Hibernate initial release date is May 2001.

 

Top