본문 바로가기

⭐🌏 JPA/🌏 Spring Error

[ERROR] No results were returned by the query.

# No results were returned by the query.

해결방법에 대해서 알아보자.

내용은 쿼리에대한 반환값이 없다는 내용이다.

 

- 해결방법 (제대로된 해결인지는 모르겠다.)

- 반환값을 int로 받는다.

1. Controller

    /** 회원가입 정보 INSERT - NativeQuery */
    @PostMapping("/joinMembershipNative")
    public GeneralResponse<?> joinMembershipNative(@RequestParam(value = "id") Long id,
                                                   @RequestParam(value = "description") String description,
                                                   @RequestParam(value = "title") String title) {
        return boardService.joinMembershipNative(id, description, title);
    }
}

2. Service

    public GeneralResponse<?> joinMembershipNative(Long id, String description, String title) {
        int boardEntityList = boardRepository.joinMembershipNative(id, description, title);
        System.out.println("값을 테스트 합니다" + boardEntityList);
        return GeneralResponse.builder()
                .status(true)
                .message("insert into T (C,C,C) VALUES(V,V,V)")
                .data("회원 정보가 추가 되었습니다.")
                .build();
    }

3. Repository

    @Transactional
    @Modifying
    @Query(value = "insert into board (id, description, title) VALUES( :id, :description, :title)", nativeQuery = true)
    int joinMembershipNative(@Param("id") Long id,
                             @Param("description") String description,
                             @Param("title") String title);

4. 결과

5. DB 확인

- 끗 -