Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate空间生成中的JTS几何体“错误:内部(几何体,bytea)的函数不存在”_Java_Spring Boot_Postgis_Hibernate Spatial - Fatal编程技术网

Java Hibernate空间生成中的JTS几何体“错误:内部(几何体,bytea)的函数不存在”

Java Hibernate空间生成中的JTS几何体“错误:内部(几何体,bytea)的函数不存在”,java,spring-boot,postgis,hibernate-spatial,Java,Spring Boot,Postgis,Hibernate Spatial,Hibernate spatial 5.4.22,Hibernate.dial=org.Hibernate.space.dial.postgis.postgisdial 一个非常简单的查询: import org.locationtech.jts.geom.Geometry; ... @Query(value = "Select s from #{#entityName} s where within(s.shape, :bounds )= true") public

Hibernate spatial 5.4.22,Hibernate.dial=org.Hibernate.space.dial.postgis.postgisdial

一个非常简单的查询:

    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);
但它会产生错误

    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形状字段是几何ok。它是postgis几何体类型,但无法理解JTS几何体对象。我看到了许多关于相反的问题,但不是这个错误。

PostGisDialante已经被弃用了相当长一段时间。您应该为Postgis使用一种较新的方言,例如PostGispg95方言。您应该在SQL函数中看到st_in函数,而不是内函数。

多亏了@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);

我正在关注Hibernate spatial文档。Hibernate Spatial扩展了Hibernate ORM方言,以便在HQL和JPQL中提供数据库的空间功能。例如,我们没有使用PostgreSql82方言,而是使用该方言的Hibernate空间扩展,即PostGis方言。该文档也在内部使用,而不是在内部使用。如果文档已过期,最佳信息来源在哪里?确定。在properties中尝试了此操作:hibernate.dialen=org.hibernate.spatial.dialen.postgis.postgisdialent-spring.jpa.properties.hibernate.dialen=org.hibernate.spatial.dialen.postgispg95现在代码运行-查询不工作,但这可能是另一个问题。是的,HQL/hibernate函数在,但是它被翻译成PSQL SQL,作为st_in。
@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);