본문 바로가기

⭐🌏 JPA/🌏 Native Query

No results were returned by the query. 해결하기

# No results were returned by the query. 발생 시 해결방법

- 이전에 JPA에서 오류나서 처리한 내역은 아래와 같다. 처리 내용도 아래와 같다. 중복이다...ㅋㅋ

2022.08.26 - [⭐🌏 JPA/🌏 Spring Error] - [ERROR] No results were returned by the query.

 

[ERROR] No results were returned by the query.

# No results were returned by the query. 해결방법에 대해서 알아보자. 내용은 쿼리에대한 반환값이 없다는 내용이다. - 해결방법 (제대로된 해결인지는 모르겠다.) - 반환값을 int로 받는다. 1. Controller /**..

may9noy.tistory.com

API 개발을 하다보면, No results were returned by the query. 이와 같은 오류가 발생하는 경우가 많다.

주로 POST나 DELETE, PATCH를 할때 발생한다.

 

- 구글을 검색해보니 비슷한 오류를 겪는 사람들이 많더라...

https://okky.kr/articles/392777

 

OKKY - postgresql 에러 궁금합니다~

jsp에서 db에 붙어서 INSERT문을 날리는데... DB에는 정상적으로 데이터가 들어가는데,콘솔창에는 에러난다고 하네요..No results were returned by the query.요 에러가 발생합니다. 아래는 스택트레이스 전체

okky.kr

1. 오류내용 보기

2. 해결방법

- 위의 OKKY의 댓글에서 알려준것 처럼 타입을 int형으로 바꾼다.

아래와 같이 서비스와 레파지토리의 타입을 int형으로 바꾼다.

UserService 의 내용

    public GeneralResponse<?> delete_user(Long userid) {
        int userEntityList = userRepository.delete_user(userid);
        System.out.println(userEntityList);
        return GeneralResponse.builder()
                .status(true)
                .message("Delete user")
                .data("회원 정보가 삭제 되었습니다.")
                .build();
    }

- UserRepository 의 내용

    @Transactional
    @Query(value = "delete from user_table where userid = :userid", nativeQuery = true)
    int delete_user(@Param("userid") Long userid);

3. 또다른 오류 발생

- 타입을 int형으로 바꿔도 계속 같은 오류가 발생 하였다. 그래서 다시 구글링...

https://bsssss.tistory.com/m/939

 

[JPA]No results returned by the Query error in PostgreSQL

JPA 에서 repository 에서 query 문에 update를 사용하는데 아래 어노테이션이 없으면 다음과 같은 에러가 발생한다. Modifying 어노테이션을 추가해주면 된다. @Modifying 내가 작성한 코드 @Modifying @Query(va..

bsssss.tistory.com

- 레파지토리에 아래와 같이 @Modifying 어노테이션을 추가하란다.

    @Transactional
    @Modifying
    @Query(value = "delete from user_table where userid = :userid", nativeQuery = true)
    int delete_user(@Param("userid") Long userid);

4. 결과 확인

정상적으로 처리됨... 이렇게 처리하는게 맞는건지는 잘 모르겠지만~

- 끝 -