【问题标题】:Persisting spacial (Point) properties from Neo4j using java ogm使用 java ogm 从 Neo4j 持久化空间(点)属性
【发布时间】:2020-05-08 13:01:30
【问题描述】:

我有一个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' 不能作为属性持久化,但尚未标记为瞬态。

我已经为coordinates尝试了各种其他类型,并且还尝试使用转换器(基于the ogm documentation - see 3.10.2);但每次我得到一个错误。

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

注意:我知道我的点数可能应该是 4326,因为我说的是纬度和经度 - 我不确定为什么不是 - 但现在让我们按原样解决问题

【问题讨论】:

  • 你尝试过 PointValue 吗?
  • @TheCrusher 给出同样的错误

标签: java neo4j spatial neo4j-ogm


【解决方案1】:

请确保您在 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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多