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.
- Spring Data JPA Query Methods.
- Spring Data JPA greater than Example.
- Spring Data JPA less than Example
- Spring Data JPA IsNull Example Using Spring Boot
- Spring Data findById() Vs getOne()
- Spring Data JPA CrudRepository findById()
- Spring Data JPA JpaRepository getOne()
- Spring Data CrudRepository saveAll() and findAll().
- Spring Data CrudRepository existsById()
- Spring Data JPA delete() vs deleteInBatch()
- Spring Data JPA deleteAll() Vs deleteAllInBatch()
- Spring Data JPA JpaRepository deleteAllInBatch()
- Spring Data JPA deleteInBatch() Example
- Spring Data JPA JpaRepository saveAndFlush() Example
- Spring Data JPA CrudRepository count() Example
- Spring Data JPA CrudRepository delete() and deleteAll()
- Spring Data JPA CrudRepository deleteById() Example
- CrudRepository findAllById() Example Using Spring Boot
- Spring Data CrudRepository save() Method.
- Sorting in Spring Data JPA using Spring Boot.
- Spring Data JPA example using spring boot.
- Spring Data JPA and its benefit.
Other Spring Data JPA and Hibernate tutorials.
- @Version Annotation Example In Hibernate.
- Hibernate Validator Constraints Example Using Spring Boot.
- @Temporal Annotation Example In Hibernate/Jpa Using Spring Boot.
- Hibernate Table Per Concrete Class Spring Boot.
- Hibernate Table Per Subclass Inheritance Spring Boot.
- Hibernate Single Table Inheritance using Spring Boot.
Spring JPA docs.
Summary – We have seen JPA vs Hibernate.
- Java Persistent API (JPA) is an only specification which provides different API which further can be used with
- Hibernate
- TopLink
- JDO
- Eclipselink
- We can consider JPA as an interface whereas hibernate is the implementation of those interfaces.
- The initial release date of the JPA 1.0 specification is May 2006 whereas Hibernate initial release date is May 2001.