使用 java ogm 保留 Neo4j 的空间(点)属性

Persisting spacial (Point) properties from Neo4j using java ogm

我有一个neo4j数据库,数据库中的一个节点有以下内容:

<id>:91671 coordinates: point({srid:7203, x:-4.327197062, y:52.03857589}) description: "home"

我正在尝试在 java 中制作这个模型 - 所以:

import org.neo4j.ogm.annotation.GeneratedValue;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Property;
import org.neo4j.ogm.types.spatial.CartesianPoint2d;

@NodeEntity (label="Location")
public class Location
{
    @Id @GeneratedValue
    private Long id;

    public Long getId() 
    {
        return id;
    }  

    @Property(name="description")
    String description;

    @Property(name="coordinates")
    CartesianPoint2d coordinates; // problem is here      
}

当我尝试使用 ogm 将节点映射到对象时,出现以下错误:

org.neo4j.ogm.exception.core.InvalidPropertyFieldException: 'Location#coordinates' is not persistable as property but has not been marked as transient.

我为 coordinates 尝试了各种其他类型,也尝试过使用转换器(基于 the ogm documentation - see 3.10.2);但是每次我都会出错。

在 srid 7203 的 neo4j Point 和 java 中的类型之间进行此映射的正确方法是什么?为什么说它不可持久化,我的替代方案是什么?

注意:我知道我的点数可能应该是 srid 4326,因为我在谈论纬度和经度 - 我不确定为什么它们不是 - 但让我们解决这个问题-暂时

请确保您在 ogm 属性中启用了本机类型

use-native-types=true

或在配置生成器中

Configuration configuration = new Configuration.Builder()
        .uri("bolt://neo4j:password@localhost")
        .useNativeTypes()   //this enables using the spatial and temporal data 
        .build()            //  types in ogm 

并在您的 pojo 中使用 CartesianPoint2d/CartesianPoint3d 或 GeographicPoint2d/GeographicPoint3d,具体取决于图表中的数据类型。

@Property(name="coordinates")
CartesianPoint2d coordinates;