0

i am using postgis with spring boot hibernate jpa.

Code in Repository:

@Query(value = "select {h-schema}ref_plz_geom.plz from {h-schema}ref_plz_geom WHERE ST_Contains(geom, ST_Transform(ST_GeomFromText('POINT(:userLongitude :userLatitude)',4647),4326))", nativeQuery=true)

String getPlz(Double userLongitude, Double userLatitude);

i get the following error :

2023-01-10 14:44:08,479 ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: parse error - invalid geometry
  Hint: "POINT(:u" <-- parse error at position 8 within geometry

When i run the same query in postgres i get the pincode:

select
        pincode 
    from
        pin_code_table
    WHERE
        ST_Contains(geom, ST_Transform(ST_GeomFromText('POINT(32528808.761501245 5471624.355)',4647),4326))

But when i run the sring boot application , i get the above error.Please advice.

JGH
  • 15,928
  • 4
  • 31
  • 48
JavDevHar
  • 1
  • 1
  • On a side note, you can use [`st_point`](https://postgis.net/docs/ST_Point.html) to create the point from the coordinates, there is no need to convert to text first (and it's faster). – JGH Jan 10 '23 at 14:16

1 Answers1

0

You need to declare the parameter name:

String getPlz(@Param("userLongitude") Double userLongitude, @Param("userLatitude") Double userLatitude);
JGH
  • 15,928
  • 4
  • 31
  • 48