본문 바로가기

오류일기

[JPA] Reason: Validation failed for query for method public abstract 에러가 날 때

UnsatisfiedDependencyException이 난 결과창입니다.
어디서 터졌는지 보여주는 결과창입니다...

JPQL로 신나게 두들기다 다음과 같은 오류가 났습니다...

그리고 이는 문제의 코드 입니다.

@Query(value = "select r from Report r " +
        "where ST_Dwithin(r.location, :point, :radius, false) = true")
List<Report> findReportsWithinRadius(@Param("point") Point point, @Param("radius") double radius);

구글링을 해보니 nativeQuery = true 조건을 걸어주면 된다고 합니다...

@Query(value = "select r from Report r " +
        "where ST_Dwithin(r.location, :point, :radius, false) = true", nativeQuery = true)
List<Report> findReportsWithinRadius(@Param("point") Point point, @Param("radius") double radius);

그러나 여전히 드는 의문점은 nativeQuery 조건은 진짜 날 것 그 자체의 쿼리를 사용할때 쓰는 조건이라 알고 있는데...

저는 분명 JPQL을 사용했는데 왜 nativeQuery 조건을 주고 또 왜 올바르게 돌아가는 것인지는 모르겠습니다...ㅠㅠ

 

수정

분명 JPQL을 사용하지만 nativeQuery = true 조건을 달면 위의 에러는 사라집니다. 또한 다음과 같은 그럴듯한 에러가 발생합니다.

그리고 이를 해결하기 위한 방법으로는 애초부터 JPQL + nativeQuery = true 조건을 달아서 사용하는 것이 아닌 nativeQuery + nativeQuery = true로 해주면 됩니다.

 

아래는 수정한 native Query입니다.

@Query(value = "SELECT * FROM Report r " +
        "WHERE ST_DWithin(r.location, :point, :radius, false) = true", nativeQuery = true)
List<Report> findReportsWithinRadius(@Param("point") Point point, @Param("radius") double radius);