我已经在postgresql中创建了一个表,作为。
CREATE TABLE feature (ID serial, feature_name text, geom geometry(GEOMETRYZ,4326));
我必须使用spring对关系数据库的反应式支持(r2dbc)来读取数据。我不知道如何在java类中把geom列映射到一个字段。
我的不完整类是。
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.data.annotation.Id;
@Table
public class Feature {
@Id
private Long id;
@Column("feature_name")
private String featureName;
@Column("geom")
@Type(type="org.hibernate.spatial.GeometryType")
public com.vividsolutions.jts.geom.Geometry geom;
}
什么样的java数据类型可以映射到postgresql geometry? 怎么做呢?
编辑:spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect。
错误在代码中。
FeatureRepository featureRepository = applicationContext.getBean(FeatureRepository.class);
featureRepository.findAll().doOnNext(feature -> {
log.info(feature.toString());
}).blockLast(Duration.ofSeconds(10));
使用 com.vividsolutions.jts.geom.
这里我举一个例子 Point
@Column("geom")
private Point location;
你可以创建 Point
使用 GeometryFactory
GeometryFactory geometryFactory = new GeometryFactory();
Point point = geometryFactory.createPoint(new Coordinate(12.34343, 12.232424));
添加 hibernate-spatial
在pom.xml中
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
</dependency>
然后你需要根据你的PostgreSQL添加方言。
org.hibernate.spatial.dialect.postgis.PostgisPG9Dialect