문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
java:jpa:springdatajpa [2019/01/30 09:13] kwon37xi |
java:jpa:springdatajpa [2023/07/10 15:01] kwon37xi [Pageable 사용 금지] |
||
---|---|---|---|
줄 5: | 줄 5: | ||
* [[java: | * [[java: | ||
- | ====== 기본 Repository Interface | + | ===== 기본 Repository Interface ===== |
< | < | ||
public interface MyEntityRepository extends JpaRepository< | public interface MyEntityRepository extends JpaRepository< | ||
줄 34: | 줄 34: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | ===== Repository 상속 금지 ===== | ||
+ | * 멀티 모듈 프로젝트에서 '' | ||
+ | * 이 경우 도메인 모듈과 말단 모듈의 Repository가 둘다 Custom 구현을 필요로 할 경우 제대로 작동안하게 된다. | ||
+ | * 또한, 메소드 이름 겹칠 때 뭘 선택하게 되는지 불확실한 등 문제가 많다. | ||
+ | * 꼭 말단 모듈에서 Repository 메소드를 도메인모듈과 격리해서 구현하고자 한다면 **상속 없이 별개의 Repository로 따로 만든다.** | ||
+ | |||
+ | ===== Pageable 사용 금지 ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * Spring Data 에서 '' | ||
+ | * 이 기능은 데이터량이 적은 tutorial 프로젝트 수준에서나 쓸모 있다. | ||
+ | * 대부분의 실무 서비스는 이런 방식의 페이징을 사용하면 시스템이 사용할 수 없을 정도로 큰 부하를 일으킨다. | ||
+ | * 다른 문제 : page의 시작인 기본이 0인데 문제는 보편적인 서비스의 page 번호는 1로 시작한다. 이를 헷갈려 해서 호출자가 첫번째 페이지를 1로 호출하는 경우가 많다. 설정으로 해결 가능하나 이를 지키지 못하는 경우가 많이 발생한다. | ||
+ | |||
+ | ===== Pageable 대신 Slice 사용 ===== | ||
+ | |||
===== Native Query ===== | ===== Native Query ===== | ||
줄 122: | 줄 140: | ||
Optional< | Optional< | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ===== Exists ===== | ||
+ | * [[https:// | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Query 인자로 들어온 null 무시하기 ===== | ||
+ | * [[https:// | ||
+ | * ''? | ||
+ | <code sql> | ||
+ | (? is null or column = ?) | ||
+ | </ | ||
+ | |||
+ | ===== Projection ===== | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * interface 기반으로 projection 가능. | ||
+ | |||
+ | ===== @Query에 SpEL 지원 ===== | ||
+ | * [[https:// | ||
+ | |||
+ | <code java> | ||
+ | @Query(" | ||
+ | List< | ||
+ | |||
+ | @Query(" | ||
+ | List< | ||
</ | </ | ||
줄 129: | 줄 175: | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
+ | * https:// | ||
+ | * [[https:// | ||
+ | * [[https:// |