Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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
Hibernate postgis和h2gis的Jpa查询_Hibernate_Jpa_H2_Postgis - Fatal编程技术网

Hibernate postgis和h2gis的Jpa查询

Hibernate postgis和h2gis的Jpa查询,hibernate,jpa,h2,postgis,Hibernate,Jpa,H2,Postgis,我在JpaRepository中有查询,它使用Postgis函数,如ST_MakeEnvelope、ST_DWithin等,这是用于生产代码的 我还想为H2gis测试这些查询,但是这些函数在那时不起作用 如何使用hibernate spatial弥补这一差距 我的问题如下: @Query(value = "SELECT * FROM Feature f WHERE geometry && ST_MakeEnvelope(:west, :south, :east, :north,

我在JpaRepository中有查询,它使用Postgis函数,如ST_MakeEnvelope、ST_DWithin等,这是用于生产代码的

我还想为H2gis测试这些查询,但是这些函数在那时不起作用

如何使用hibernate spatial弥补这一差距

我的问题如下:

@Query(value = "SELECT * FROM Feature f WHERE geometry && ST_MakeEnvelope(:west, :south, :east, :north, :srid)", nativeQuery = true)
如何使其与h2 gis一起工作

所以我创建了这个查询:

@Query(value = "SELECT * FROM Feature f where dwithin(f.geometry, :centre, :range)", nativeQuery = true)
但这带来了错误:

Caused by: org.h2.jdbc.JdbcSQLException: Function "DWITHIN" not found;
我有以下依赖项:

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.orbisgis</groupId>
            <artifactId>h2gis-functions</artifactId>
            <version>1.3.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-spatial</artifactId>
            <version>5.4.17.Final</version>
        </dependency>

com.h2数据库
氢
1.4.197
测试
org.orbisgis
h2gis功能
1.3.2
测试
org.hibernate
冬眠空间
5.4.17.最终版本

更新H2GIS的最新版本。在最新版本中,此问题已修复

<dependency>
   <groupId>org.orbisgis</groupId>
   <artifactId>h2gis</artifactId>
   <version>1.5.0</version>
</dependency>
然后使用like

@Query(value = "SELECT * FROM Feature f where ST_DWithin(f.geometry, :centre, :range)", nativeQuery = true)

您是否为spatial初始化h2 db?是的,我的保存操作运行良好,并且可以读取。问题是只有当读取查询使用了空间函数时,您才能尝试使用
ST_DWithin
而不是
DWithin
尝试过。这也会引发同样的错误。我的意思是h2 gis扩展函数初始化了吗?类似于为“org.H2GIS.functions.factory.H2GISFunctions.load”创建别名(如果不存在);调用H2GIS_SPATIAL();找不到此依赖项此页面提供了依赖项,但它们似乎不可用或不兼容。您对org.locationtech.jts的依赖项是什么?您正在使用
com.lividsolutions.jts.geom.Geometry
right?org.locationtech.jts.Geometry
@Query(value = "SELECT * FROM Feature f where ST_DWithin(f.geometry, :centre, :range)", nativeQuery = true)