JPA
JPA implementations/providers
- Hibernate
- EclipseLink
- Apache OpenJPA
- TopLink
- JDO
Spring Data JPA
Hibernate
Spring Data JPA and Hibernate
- With Hibernate you get:
- 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 the above plus:
- 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
- Spring Data JPA adds an extra layer of abstraction on the top of our JPA provider like Hibernate
Libraries
org.springframework.boot:spring-boot-starter-data-jpa
- It includes spring data, hibernate, HikariCP, JPA API, JPA Implementation (default is hibernate), JDBC and other required libraries.
com.h2database:h2 (for H2 database)
mysql:mysql-connector-java (for MySQL)
org.springframework.boot:spring-boot-starter-data-mongodb (MongoDB)
More to discover
- EntityManager and SessionFactory
- Entity vs Table
- JPQL
- Native Query
- Parametrized Query
- Pagination
Transactions
Object–relational impedance mismatch
- Set of difficulties going between data in relational data stores and data in domain-driven object models.