Postgis空间功能不适用于hibernate
我对JPareSposition进行了本机查询,如:Postgis空间功能不适用于hibernate,hibernate,postgis,Hibernate,Postgis,我对JPareSposition进行了本机查询,如: @Query(value = "SELECT * FROM Feature f WHERE f.feature_type = :featureType AND " + "ST_DWithin(geometry, 'SRID=:srid;POINT(:lon :lat 0)', :range)", nativeQuery = true) 生成的查询如下所示: SELECT * FROM Feature f WHERE
@Query(value = "SELECT * FROM Feature f WHERE f.feature_type = :featureType AND " +
"ST_DWithin(geometry, 'SRID=:srid;POINT(:lon :lat 0)', :range)", nativeQuery = true)
生成的查询如下所示:
SELECT * FROM Feature f WHERE f.feature_type = ? AND ST_DWithin(geometry,'SRID=:srid;POINT(:lon :lat 0)', ?)
几何图形是表中包含空间数据的列
但跟踪还表明查询存在解析错误:
Hint: "SR" <-- parse error at position 2 within geometry
您是字符串文本中的绑定参数,这就是为什么不替换任何绑定参数
'SRID=:srid;POINT(:lon :lat 0)'
您可以使用此数据创建一个字符串,并在方法中传递整个字符串
另一种方法是使用数据库concat操作,但参数必须是字符串
'SRID=' || :srid|| ';POINT(' || :lon ||' ' || :lat || ' 0)'
完全查询类
@Query(value = "SELECT * FROM Feature f WHERE f.feature_type = :featureType AND " +
"ST_DWithin(geometry, 'SRID=' || :srid || ';POINT(' || :lon ||' ' || :lat || ' 0)', :range)", nativeQuery = true)
或者使用数据库功能
ST_DWithin(geometry, ST_SetSRID(ST_Point( :lon, :lat), :srid), :range)
此抛出:由:org.postgresql.util.PSQLException引起:错误:函数st_dwithin(几何体、文本、双精度)不是唯一提示:无法选择最佳候选函数。您可能需要添加显式类型转换。传递字符串可能会有所帮助。请检查函数定义是否正确。基于数据,函数是否不唯一。显然你传递数据的问题很奇怪。Fcuntion有两个不同的变量,参数的数量不同。下面是
st_dwithin
函数的第一个参数是什么?
ST_DWithin(geometry, ST_SetSRID(ST_Point( :lon, :lat), :srid), :range)