JPA 에서 제공하는 Projection 은 FindAll() 메서드 정의시 리턴타입 오류가 난다. 이는 SimpleJpaRepository 에 정의된 내용 때문인 것 같다.
이를 회피하기위해서 FindAll~By() 로 메서드를 작성하여 사용한다.
이를 찾아본 이유는 Pagable , QueryDSL 과 연계하고 싶어서 이다.
//프로젝션
public interface PostSummary {
Long getId();
String getSubject();
Long getAccountId();
String getAuthor();
LocalDateTime getRegisterDate();
LocalDateTime getUpdateDate();
}
//리포지토리
public interface PostRepository extends JpaRepository<Post,Long>, QuerydslPredicateExecutor<Post> {
List<PostSummary> findAllPostSummaryBy();
}
//
@Test
@Rollback(value = false)
public void summaryTest(){
List<PostSummary> postsAll = postRepository.findAllPostBy();
}
'작업하면서 배우는 것들' 카테고리의 다른 글
QueryDsl Left Outer Join, Tuple, Projections (0) | 2020.12.27 |
---|---|
QueryDsl 과 커스텀 리포지토리를 이용한 쿼리문 사용 (0) | 2020.12.27 |
Vue Router 와 Href 속성 (0) | 2020.12.24 |
Axios 사용 시 Zipkin 로그 트레이싱을 위한 wrapAxios (0) | 2020.12.23 |
Uncaught ReferenceError: regeneratorRuntime is not defined (0) | 2020.12.23 |