将postgresql几何体列映射到java对象中的字段

将postgresql几何体列映射到java对象中的字段,postgresql,spring-boot,postgis,Postgresql,Spring Boot,Postgis,我在postgresql中创建了一个表,如下所示: CREATE TABLE feature (ID serial, feature_name text, geom geometry(GEOMETRYZ,4326)); 我必须使用spring对关系数据库(r2dbc)的反应式支持来读取数据。 我不知道如何将geom列映射到java类中的字段 我不完整的课程是: import org.springframework.data.relational.core.mapping.Column; imp

我在postgresql中创建了一个表,如下所示:

CREATE TABLE feature (ID serial, feature_name text, geom geometry(GEOMETRYZ,4326));
我必须使用spring对关系数据库(r2dbc)的反应式支持来读取数据。 我不知道如何将geom列映射到java类中的字段

我不完整的课程是:

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几何体?怎么做

编辑: spring.jpa.properties.hibernate.dialen=org.hibernate.spatial.dialen.postgis.postgisdialen

错误代码为:

FeatureRepository featureRepository = applicationContext.getBean(FeatureRepository.class);
        featureRepository.findAll().doOnNext(feature -> {
            log.info(feature.toString());
        }).blockLast(Duration.ofSeconds(10));
使用

这里我举一个
点的例子

@Column("geom")
private Point location;
您可以使用
GeometryFactory

GeometryFactory geometryFactory = new GeometryFactory();
Point point = geometryFactory.createPoint(new Coordinate(12.34343, 12.232424));
在pom.xml中添加
hibernate space

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-spatial</artifactId>
    </dependency>

你好。您希望几何图形采用哪种格式?WKT、GeoJSON、KML等。我正在寻找GeoJSON。我对spring boot不是很熟悉,但如果你能将函数传递到
geom
列,你可以尝试
ST_AsGeoJSON(geom)
。我以前也见过这种语法:
@Column(name=“geom”,columnDefinition=“geometry(Point,4326)”)
我将字段作为几何体,它给出了错误:原因:java.lang.IllegalStateException:找不到com.liveSolutions.jts.geometry类所需的标识符属性@列(“geom”)@Type(Type=“org.hibernate.spatial.GeometryType”)public com.lividsolutions.jts.geom.Geometry-geom;spring.jpa.properties.hibernate.dialogue=org.hibernate.spatial.dialogue.postgis.postgisdialogue您的PostgreSQL版本是什么?当您保存错误时?它是Postgresql 12,而我在读取记录时会出错。数据库表中已存在记录。我使用的是spring boot r2dbc support.yup,已提出。感谢所有的投入。
org.hibernate.spatial.dialect.postgis.PostgisPG9Dialect