java - Hibernate 空间中的 JTS 几何生成“错误:(几何,bytea)中的函数不存在”
问题描述
休眠空间 5.4.22,hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect
一个非常简单的查询:
import org.locationtech.jts.geom.Geometry;
...
@Query(value = "Select s from #{#entityName} s where within(s.shape, :bounds )= true")
public List<SiteModel> findWithinBounds(Geometry bounds);
边界几何由以下方式生成:
GeometryFactory gf = new GeometryFactory();
Polygon bounds = gf.createPolygon(sc);
bounds.setSRID(4326);
return newSiteService.findWithinBounds(bounds);
但它会产生错误
select
sitemodel0_.site_id as site_id1_1_,
sitemodel0_.accuracy as accuracy2_1_,
sitemodel0_.comment as comment3_1_,
sitemodel0_.country_code as country_4_1_,
sitemodel0_.directions as directio5_1_,
sitemodel0_.flag as flag6_1_,
sitemodel0_.height as height7_1_,
sitemodel0_.h_accuracy as h_accura8_1_,
sitemodel0_.h_method_id as h_method9_1_,
sitemodel0_.latitude as latitud10_1_,
sitemodel0_.longitude as longitu11_1_,
sitemodel0_.method_id as method_12_1_,
sitemodel0_.orig_coord as orig_co13_1_,
sitemodel0_.orig_system_id as orig_sy14_1_,
sitemodel0_.owner_id as owner_i15_1_,
sitemodel0_.shape as shape16_1_,
sitemodel0_.site_name as site_na17_1_
from
sc.site_proposed sitemodel0_
where
within(sitemodel0_.shape, ?)=true
WARN : SQL Error: 0, SQLState: 42883
ERROR: ERROR: function within(geometry, bytea) does not exist
所以似乎发现 postgis 形状字段是几何形状的。(它是 postgis 几何类型),但无法理解 JTS 几何对象。我见过很多关于相反的问题,但没有看到这个错误。
解决方案
感谢@Karel Maesen 的提示,我确实让它工作了。我需要把
hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jpa.properties.hibernate.dialect = org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
进入属性。完成后,空间查询,with 和 dwithin 都可以工作。
@Query(value = "Select s from #{#entityName} s where within(s.shape, :bounds )= true")
public List<SiteModel> findWithinBounds(Geometry bounds);
@Query(value = "Select s from #{#entityName} s where dwithin(s.shape, :point, :distance)= true")
public List<SiteModel> findCloseTo(Geometry point, double distance);
推荐阅读
- python - 如何根据 MultiIndex 的一部分将 DataFrame 拆分为多个 DataFrame?
- mysql - 如何根据条目对 ON DELETE 有不同的行为?
- python - 切片 3D 数组与投影
- python - 如何使计数器上升到某个值然后重置为 0?
- lambda - Kafka-stream:如何通过从值列表中选择键来重新设置流的键
- api - 带有质询的 Webhook URL 验证
- python - 在列表中的项目中查找字符的索引 - Python3
- javascript - 输入中的文本出现在页面的其他位置
- delphi - 如何在 Delphi 中创建 Material Design 调色板
- python - 创建时的 PrimaryKeyField 和获取时的 SerialzerField