Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 328
CuriousMind Avatar asked May 03 '16 19:05

CuriousMind


People also ask

What is the difference between Hibernate and data JPA?

JPA uses EntityManager interface to create/read/delete operation and maintains the persistence context. Hibernate uses Session interface to create/read/delete operation and maintains the persistence context. JPA uses JPQL (Java Persistence Query Language) as Object Oriented Query language for database operations.

Does Spring data JPA include Hibernate?

This is the type of code Spring Data JPA helps to avoid. Spring Data JPA is really a set of dependencies that makes it easier to work with a JPA provider. Hibernate is one of several JPA providers. This means you can use Spring Data JPA without using Hibernate (if you really wanted to).

Is Hibernate and JPA same?

Conclusion: The major difference between Hibernate and JPA is that Hibernate is a framework while JPA is API specifications. Hibernate is the implementation of all the JPA guidelines.

What is the difference between spring JPA and Spring data JPA?

Spring Data JPA is a JPA data access abstraction. Just like JPA, Spring Data JPA cannot work without a JPA provider. Spring Data JPA offers a solution to the DDD Repository pattern or the DAO (Data Acess Object) pattern . It can also generate JPA queries on your behalf through method name conventions.


1 Answers

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.

like image 76
JB Nizet Avatar answered Sep 23 '22 23:09

JB Nizet