显然,对于Hibernate 5,支持地理类型。我经常搜索,但发现与地理点无关。
我想做的是以下内容:
ST_GeomFromText('POINT(6.463471 52.484832)', 4326)
WHERE point && ST_MakeEnvelope (5.440433, 39.480434, 8.464680, 55.486190, 4326)
我正在使用PostgreSQL和PostGIS。
我只是找不到哪种类型的hibernate列注释我必须使用它来获取Long / Lat Points,以及如何执行上述查询。
@Type(type="org.hibernate.spatial.GeometryType")
关于Long / Lat不是重点
有没有关于此的文件(注意:不是几何点)。
是的,Hibernate 5支持Spatial。
您需要添加依赖项
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>5.2.17.Final</version><!-- In my case was this version, needs to match with your hibernate core version-->
</dependency>
然后你需要根据你的PostgreSQL版本使用正确的方言。
它们的清单:
org.hibernate.spatial.dialect.postgis.PostgisPG9Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG82Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG91Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG92Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG93Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG94Dialect
org.hibernate.spatial.dialect.postgis.PostgisPG95Dialect
设置正确的方言后,您可以在实体中使用Point或Polygon(不需要使用@Type)。它们包含在com.vividsolutions.jts.geom包中
创建一个点:
GeometryFactory gf = new GeometryFactory();
Point point = gf.createPoint(new Coordinate(lat, lon));