Spring Data Rest - Neo4j - 无法推出具有@StartNode和@EndNode的新关系

时间:2016-02-09 15:30:39

标签: neo4j spring-data spring-data-rest spring-data-neo4j-4

我有以下域名模型:

路线实体:

package org.gmjm.logistics.domain;

import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;

@RelationshipEntity(type="ROUTE")
public class Route
{
    @GraphId
    private Long routeId;

    private Long latencyInMinutes;

    @StartNode
    private Hub originHub;

    @EndNode
    private Hub destinationHub;

    //Getters & Setters
}

中心实体:

package org.gmjm.logistics.domain;

import java.util.Collection;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;

@NodeEntity
public class Hub
{
    @GraphId
    private Long nodeId;

    private String hubName;

    private Long x;
    private Long y;

    @Relationship(type="ROUTE",direction= Relationship.INCOMING)
    private Collection<Route> incomingRoutes;

    @Relationship(type="ROUTE",direction=Relationship.OUTGOING)
    private Collection<Route> outgoingRoutes;
}

以下存储库:

package org.gmjm.logistics.repository;

import org.gmjm.logistics.domain.Hub;
import org.springframework.data.neo4j.repository.GraphRepository;

public interface HubRepository extends GraphRepository<Hub>
{
}

public interface RouteRepository extends GraphRepository<Route>
{
}

以下是其他重要文件的链接,在Gist上节省空间:
DemoNeo4jConfig.java
SpringDataNeo4jDemoApplication
build.gradle

我遇到了以下异常,并尝试了很多不同的方法来实现这一点。以前用弹簧数据休息,以这种方式发布关系,我从来没有遇到过这样的问题。

将JSON发布到http:localhost:8080 / routes

{
    "latencyInMinutes" : 1500,
    "originHub" : "http://localhost:8080/hubs/1044",
    "destinationHub" : "http://localhost:8080/hubs/1045"
}

例外:

{
  "cause": {
    "cause": null,
    "message": "Can not instantiate value of type [simple type, class org.gmjm.logistics.domain.Hub] from String value ('http://localhost:8080/hubs/1044'); no single-String constructor/factory method\n at [Source: HttpInputOverHTTP@207155db; line: 2, column: 30] (through reference chain: org.gmjm.logistics.domain.Route[\"originHub\"])"
  },
  "message": "Could not read document: Can not instantiate value of type [simple type, class org.gmjm.logistics.domain.Hub] from String value ('http://localhost:8080/hubs/1044'); no single-String constructor/factory method\n at [Source: HttpInputOverHTTP@207155db; line: 2, column: 30] (through reference chain: org.gmjm.logistics.domain.Route[\"originHub\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class org.gmjm.logistics.domain.Hub] from String value ('http://localhost:8080/hubs/1044'); no single-String constructor/factory method\n at [Source: HttpInputOverHTTP@207155db; line: 2, column: 30] (through reference chain: org.gmjm.logistics.domain.Route[\"originHub\"])"
}

(服务器堆栈)[https://gist.github.com/aglassman/0eb32f371cb2c556543d]

我尝试过显而易见的事情,例如添加一个构造函数,其中包含一个解析为ID的字符串,另一个构建了hubName,还有一些其他组合。我猜测我可以使用一些JSON注释来解决这个问题,但我无法在文档中找到任何内容。有什么想法吗?

0 个答案:

没有答案