[Spring Data JPA] No property desc/asc found for type Error

스브코·2022년 3월 19일
0

JPA쿼리 메소드를 작성해서 사용하다 보면 위 제목과 같은 에러가 발생한다.


프로젝트를 하던 도중....

List<Product> findAllOrderByCreatedAtDesc();

위와 같이 쿼리 메소드를 만들어주었는데, 아래와 같이 에러가 발생했다.

findAllOrderByCreatedAtDesc()! No property 'desc' found for type 'LocalDateTime'! Traversed path: Product.createdAt.


해결 방법은 간단한데, 아래와 같이 All과 Order 사이에 By를 넣어서 바꾸어 주면 된다.

List<Product> findAllByOrderByCreatedAtDesc();


영어로 봐도 되게 이상한 wording인데 Sping data jpa 이슈 보드에서 설명한 이유에 따르면,

The first "By" in a query method indicates the start of a path expression.

첫번째 "By"가 경로의 시작점을 잡아주기 때문이라고 한다..


출처: https://github.com/spring-projects/spring-data-jpa/issues/1174

profile
익히는 속도가 까먹는 속도를 추월하는 그날까지...

0개의 댓글