Implementation with and without using Spring Data JPA
Inject EntityMangager
into Repository
implementation class.
Each operation method is implemented in the Repository
.
Each method delegate actual process to EntityManager
.
Their signatures imitate ones of JpaRepository
provided by Spring Data JPA.
This is based on Spring Boot and @EnableJpaRepositories
is enabled.
To avoid using Spring Data JPA, I use @Profile
on Service
classes.
I have 2 Service
classes. One is for without Spring Data JPA, the other is for Spring Data JPA.
- Set profile "without-datajpa" into application.yml
- Run main method in
Application
- Access http://localhost:8080/rooms
- Confirm JPA mode at the bottom of web pages. It might show
RoomServiceImpl
.
Basic usage of Spring Data JPA. Spring Boot helps configurations for Spring Data JPA. But I dare to have configuration code for Spring Data JPA for learning its mechanism.
- Set profile empty or anything other than "without-datajpa" into application.yml
- Run main method in
Application
- Access http://localhost:8080/rooms
- Confirm JPA mode at the bottom of web pages. It might show
RoomServiceJpaImpl
.