What are the main differences between Hibernate and Spring Data JPA? When should we not use Hibernate or Spring Data JPA? Also, when may Spring JDBC template perform better than Hibernate / Spring Data JPA?
Java – the difference between Hibernate and Spring Data JPA
hibernatejavajpaspringspring-data-jpa
Related Topic
- Java – Difference between StringBuilder and StringBuffer
- Java – What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do
- Java – the difference between JDK and JRE
- Java – What’s the difference between @Component, @Repository & @Service annotations in Spring
- Java – Why is processing a sorted array faster than processing an unsorted array
- Java – difference between CrudRepository and JpaRepository interfaces in Spring Data JPA
- Java – the difference between canonical name, simple name and class name in Java Class
Best Answer
Hibernate is a JPA implementation, while Spring Data JPA is a JPA data access abstraction. Spring Data JPA cannot work without a JPA provider.
Spring Data offers a solution to the DDD
Repository
pattern or the legacyGenericDao
custom implementations. It can also generate JPA queries on your behalf through method name conventions.With Spring Data, you may use Hibernate, EclipseLink, or any other JPA provider. A very interesting benefit of using Spring or Java EE is that you can control transaction boundaries declaratively using the
@Transactional
annotation.Spring JDBC is much more lightweight, and it's intended for native querying, and if you only intend to use JDBC alone, then you are better off using Spring JDBC to deal with the JDBC verbosity.
Therefore, Hibernate and Spring Data are complementary rather than competitors.