JDBC, JPA, Hibernate, JPARepository, PagingAndSortingRepository, CrudRepository

Nil Seri
2 min readNov 12, 2021

Short descriptions of JDBC, JPA, Hibernate, JPARepository, PagingAndSortingRepository and CrudRepository to give an idea where to use which

Photo by Nick Fewings on Unsplash

JDBC — JPA — Hibernate

JDBC (Java Database Connectivity) is an interface that communicate with a database. It’s the common API that our application code uses to communicate with the database.

JPA (Java Persistence API) is a Java standard that allows us to bind Java objects to records in a relational database (ORM — Object Relationship Mapping) by allowing to retrieve, store, update, and delete data in a relational database using these objects.

JPA serves as a layer of abstraction that hides the low-level JDBC calls from the developer, making database programming considerably easier.

Hibernate is an open-source, light-weight Java ORM framework. It is an implementation of JPA.

JPARepository — PagingAndSortingRepository — CrudRepository

There is a fine definition and a table for comparison here.

https://www.tutorialspoint.com/difference-between-crudrepository-and-jparepository-in-java

As an extra point, querying methods return List instead of Iterable in JpaRepository.

JpaRepository contains the full API of CrudRepository and PagingAndSortingRepository.

JpaRepository Interface (spring-data-jpa:2.5.6):

Spring Data JpaRepository Interface

PagingAndSortingRepository Interface (spring-data-commons:2.5.6):

PagingAndSortingRepository Interface

CrudRepository Interface (spring-data-commons:2.5.6):

Spring Data CrudRepository Interface

There are also store-specific interfaces which eventually tighten the coupling when used so be careful choosing.

IT Crowd — Moss

Happy Coding!

--

--

Nil Seri

I would love to change the world, but they won’t give me the source code | coding 👩🏻‍💻 | coffee ☕️ | jazz 🎷 | anime 🐲 | books 📚 | drawing 🎨