관리 메뉴

개발하는 동그리

For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.; nested exception is java.lang.IllegalStateException: For queries with name.. 본문

IT 정보/Error

For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.; nested exception is java.lang.IllegalStateException: For queries with name..

개발하는 동그리 2022. 8. 31. 21:17
반응형
public interface PostsRepository extends JpaRepository<Posts, Long> {

    @Modifying
    @Query("update Posts p set p.view = p.view + 1 where p.postsId = :postsId")
    int updateView(Long postsId);

}

Repository Query 오류 발생시 

For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.; nested exception is java.lang.IllegalStateException: For queries with named parameters you need to use provide names for method parameters. Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters. 

아래와 같은 오류가 뜬다. 

이때 해결 방법은 

public interface PostsRepository extends JpaRepository<Posts, Long> {

    @Modifying
    @Query("update Posts p set p.view = p.view + 1 where p.postsId = :postsId")
    int updateView(@Param("postsId") Long postsId); 

}

아래 코드와 같이 @Param("postsId") 을 입력해주면 해결 된다. 

반응형