쇼핑몰 프로젝트를 하던 중, 다음과 같은 오류가 발생하였다.
Caused by: 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
JPQL을 사용할 때, 발생되는 것으로 추정되었고, 당시의 나는 아래와 같은 레파지토리를 작성해뒀다.
@Query("SELECT new com.shop.dto.CartDetailDto(ci.id, i.itemNm, i.price, ci.count, im.imgUrl) " +
"FROM CartItem ci, ItemImg im " +
"JOIN ci.item i " +
"WHERE ci.cart.id = :cartId " +
"AND im.item.id = ci.item.id " +
"AND im.repImgYn = 'Y' " +
"ORDER BY ci.regTime DESC" )
List<CartDetailDto> findCartDetailDtoList(Long cartId);
검색 결과로는 @Param을 설정해라는 방식과 옵션에서 -parameters를 추가해라는 방식이 있었는데, 후자의 방법은 개인적으로 환경이 바뀌면 또 같은 상황이 일어나기 때문에 옳지 않다고 판단하였다.
@Param을 쓰는 방식으로 아래와 같이 수정하였다.
@Query("SELECT new com.shop.dto.CartDetailDto(ci.id, i.itemNm, i.price, ci.count, im.imgUrl) " +
"FROM CartItem ci, ItemImg im " +
"JOIN ci.item i " +
"WHERE ci.cart.id = :cartId " +
"AND im.item.id = ci.item.id " +
"AND im.repImgYn = 'Y' " +
"ORDER BY ci.regTime DESC" )
List<CartDetailDto> findCartDetailDtoList(@Param("cartId")Long cartId);
이후, IllegalStateException이 발생하지 않게 되었다.
'Java, Spring > Errors' 카테고리의 다른 글
java.lang.NoSuchMethodError: org.thymeleaf.context.IWebContext.getExchange()Lorg/thymeleaf/web/IWebExchange; (0) | 2023.05.23 |
---|