2

I am trying to query spatial data using the below native query. and I am getting below exception in doing so.

@Query(nativeQuery = true, value = "SELECT \* FROM locations WHERE ST_Contains(polygon, ST_Transform(ST_SetSRID(ST_MakePoint(:x, :y), 4326), 3785))")
List\<Location\> test(@Param("x") double x,@Param("y") double y);

Exception I am getting

ERROR: function st_makepoint(double precision, double precision) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.

tried adding the below configs

hibernate-spatial dependency

properties.put("hibernate.dialect", "org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect");`

Note: If I execute same query directly on db , its working

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
noob123
  • 21
  • 2
  • Dependency used -> org.hibernate hibernate-spatial 5.6.2.Final – noob123 Apr 26 '23 at 08:00
  • Please edit your question to add more details. I tried formatting it but I am not sure if the slashes you added were to escape the site or are part of your query. Please edit to fix. – Rohit Gupta Apr 27 '23 at 11:36

1 Answers1

0

I uses myBatis and the native query as following

@Select("SELECT * FROM vehicle WHERE public.ST_DWithin(last_location::public.geography, public.ST_SetSRID(public.ST_MakePoint(#{longitude}::float, #{latitude}::float), 4326)::public.geography, #{rangeInMeter}) LIMIT #{limit}")
List\<Object\> findVehiclesInRangeFromLatLon(@Param("longitude") double longitude, @Param("latitude") double latitude, @Param("rangeInMeter") int rangeInMeter, @Param("limit") int limit);

In mybatis, using #{param} to pass the parameter to the query.

You can check on this answer for more https://stackoverflow.com/a/56888200/1721946

Lunf
  • 442
  • 4
  • 9