I have the following repository class backed by a postgres database with the postgis extension installed.
import java.util.List;
import java.util.Set;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
@Repository
public interface ForumRepository extends PagingAndSortingRepository<ForumEntity, Long> {
@Query(value = "SELECT *"
+ " FROM forums"
+ " WHERE ST_DWithin(location, 'POINT(:lon :lat)', :meters,true)"
+ " ORDER BY ST_Distance(location, 'POINT(:lon :lat)') ASC",
countQuery = "SELECT count(*) FROM forums WHERE ST_DWithin(location, 'POINT(:lon :lat)', :meters,true)",
nativeQuery = true)
List<ForumEntity> findInRadius(@Param("lat") Double lat,@Param("lon") Double lon,@Param("meters") Double meters, Pageable pageable);
}
This Spring Data JPA repository contains one method definition which queries the database to find all forums within a certain radius. I am using named params with a native query combined with postgis's ST_DWithin method to perform this query.
Spring Boot starts up fine without complaint and reports that the application has started successfully. However when I try to call that query I get the following exception - Parameter with that name [lat] did not exist; nested exception is java.lang.IllegalArgumentException: Parameter with that name [lat] did not exist
I have tried switching over to positioned parameters, but got the same error that the parameter does not exist.
I am using Spring Boot 1.5.4
Any ideas?