Post

java.lang.IllegalStateException; For queries with named parameters you need to provide names for method parameters;

id 를 명확하게 지정해 주었는지 다시 한번 확인해봅시다.

1. 에러로그

1
2
3
java.lang.IllegalStateException: For queries with named parameters you need to provide names for method parameters; 
Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters
at org.springframework.data.jpa.repository.query.QueryParameterSetterFactory$BasicQueryParameterSetterFactory.lambda$getName$2(QueryParameterSetterFactory.java:251) ~[spring-data-jpa-3.0.4.jar:3.0.4]

2. 해결

아래와 같이 @Param 을 사용하여 메서드에 알맞은 파라미터를 지정하면 됩니다.

1
2
@Query("SELECT e.category, SUM(e.expenditureAmount) FROM Expenditure e WHERE e.user.id = :userId AND e.expenditureAt BETWEEN :startDate AND :endDate GROUP BY e.category")
List<Object[]> findUserExpendituresByDateAndCategory(@Param("userId") Long userId, @Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate);
This post is licensed under CC BY 4.0 by the author.