Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

공유메모장

JPARepository? Repository? 본문

spring 공부/jpa

JPARepository? Repository?

댕칠이 2023. 7. 27. 14:26

https://velog.io/@ohzzi/JpaRepository-No-Repository-Yes

 

JpaRepository? No, Repository? Yes!

동포청년, 아직도 JpaRepository를 상속한다고?

velog.io

 

어떤 책에서는 JPARepository를 상속하여 사용하고, 어떤 책에서는 Repository만 가지고

@PersistenceContext //entity manager를 주입해줌.
private EntityManager em;

해서 사용한다. 

이 차이가 궁금해서 찾아보았다. 

그런데 결국 JpaRepository인터페이스를 구현하는 인터페이스도 entityManager를 가지고 있어야 할텐데.. JpaRepository 인터페이스나, 구현체나, 그 위로 상속받는 것들 중에 entityManager 선언이 있을 거라 생각하고 찾아보는데 아직은 못찾았다..

----------------------------------------

역시 구현체 쪽에서 EntityManager를 주입받고 있었다!

https://jaime-note.tistory.com/62

 

스프링 데이터 JPA - JPA 구현체 분석

스프링 데이터 JPA가 제공하는 공통 구현체를 분석해봅시다. SimpleJpaRepository는 JpaRepository를 구현하는 구현체로 기본적인 CRUD가 어떻게 동작하는지 확인할 수 있습니다. 약 1000 라인에 가까운 소스

jaime-note.tistory.com

 

+ 그리고 PersistenceContext와 EntityManager을 직접 주입해서 사용하는 방법은 JPA 만을 사용하는 것이고, 

JPARepository를 상속받아서 사용하는 건 Spring Data JPA 가 제공하는 기능이다!