Study/Spring
Spring JPA ) No property desc/asc found for type Error
오늘만 사는 여자
2022. 5. 9. 17:03
728x90
반응형
JPA는 JAVA ORM의 일종으로 Query를 매우 간단하게 짤 수 있는 API이다.
DB에 시간순으로 정렬된 자료를 OrderBy를 사용하여 쿼리문을 짤 때,
java.util에 있는 Date 나 LocalDateTime으로 설정된 시간을 정렬할 수없다고 한다.
List<Post> findAllOrderByCreatedatDesc();
기존 쿼리에서
List<Post> findAllByOrderByCreatedatDesc();
이처럼 All 과 Order 사이에 By를 넣어주자.
혹은
Native Query를 사용하여 정의하는 경우,
@Query(value = "SELECT * FROM posttable ORDER BY createdat DESC", nativeQuery = true)
List<post> findAllOrderByCreatedatDesc();
에서
@Query(value = "SELECT * FROM posttable p ORDER BY p.createdat DESC", nativeQuery = true)
List<Post> findAllOrderByCreatedatDesc();
로 테이블의 alias를 사용하여 정렬하면 작동된다.
출처 : https://stackoverflow.com/questions/19733464/order-by-date-asc-with-spring-data
Order By Date ASC with Spring Data
I try to make an application with Spring-Data-JPA on a table in order by ASC but it gives me an error: Invalid derived query! No property asc found for type java.util.Calendar Why ? List<Foo&...
stackoverflow.com
728x90
반응형