Spring + hibernate versus Spring Data JPA: Are they different?

CuriousMind picture CuriousMind · May 3, 2016 · Viewed 16.9k times · Source

Although not novice, I am trying to learn spring framework (again!) in order to be sure that I really understand this. I have got fair idea on core Spring (DI). Now, I am focusing on Data layer.

I have come across the term "Spring and Hibernate". As I can interpret it would mean using Spring Framework with Hibernate as ORM tool/JPA provider.

Now I have come across "Spring Data JPA". I clarified on SO about Spring Data JPA, that it is an abstraction layer on-top of JPA (and under the hood Spring Data JPA uses Hibernate or any other JPA provider).

Now are these terms same? That is, is "Spring + hibernate" same as that of "Spring Data JPA". If not, then what is the difference / similarities?

I am really confused on so many terms/statements (like above) seemingly to be similar, but may be different.

Answer

JB Nizet picture JB Nizet · May 3, 2016

Spring-data-jpa, as you're saying, offers more that just the classical Spring-JPA integration. With JPA/Hibernate integration, you get mainly

  • declarative transaction management using JPA/Hibernate transactions
  • exception translation
  • the JPA EntityManager or the Hibernate SessionFactory as injectable beans

With Spring-data-jpa, you get all that, plus (among other things)

  • interface-only repositories, using method names to infer queries automatically
  • @Query annotation to define the query that an interface method should return
  • automatic handling of Pageable queries
  • base classes for standard crud repositories

This is just a tiny introduction. For more help, read the documentation.