spring - 无法将具有 @RelatedTo 传出方向的 NodeEntity 与另一个节点一起保存

标签 spring neo4j spring-boot spring-data-neo4j

我正在使用 Spring BootNeo4J 2.1.8 ,并创建了两个 NodeEntities Parent 和 Child。 父类是

    @NodeEntity
    public class Parent{

        @GraphId
        @Indexed(indexName = "id", indexType = IndexType.FULLTEXT)
        private Long id;

        @RelatedTo(type=RelationType.IS_RELATED,direction=Direction.OUTGOING)
        @Fetch
        private Set<Child> children;


    }

子类是

@NodeEntity
public class Child{
        @GraphId
    private Long id;

    private String name;
}

parentRepochildRepo 类都扩展了 GraphRepository

现在,当创建一个在其中设置了子对象的父对象并调用 parentRepo.save(parent) 时。父实体和子实体将随着关系一起创建。

现在问题陈述是:

当父实体已创建并且我执行此操作时

Child child= new Child()
...............
Parent parent=parentRepo.retriveParent(id);
parent.getChildren().add(child);
parentRepo.save(parent);

出现以下错误:-

com.sun.jersey.api.client.ClientHandlerException: java.net.SocketTimeoutException: Read timed out
    at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149)
    at org.neo4j.rest.graphdb.UserAgent$1.handle(UserAgent.java:68)
    at com.sun.jersey.api.client.Client.handle(Client.java:648)
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:670)
    at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
    at com.sun.jersey.api.client.WebResource$Builder.put(WebResource.java:523)
    at org.neo4j.rest.graphdb.ExecutingRestRequest.put(ExecutingRestRequest.java:155)
    at org.neo4j.rest.graphdb.RestAPIImpl.setPropertiesOnEntity(RestAPIImpl.java:633)
    at org.neo4j.rest.graphdb.entity.RestEntity.flush(RestEntity.java:189)

最佳答案

好的,我明白了。我不必调用 parentRepo.save(parent) 我所做的是

childRepo.save(child);
Parent parent=parentRepo.retriveParent(id);
parent.getChildren().add(child);

节点和关系自动更新。无需显式调用parentRepo.save()

关于spring - 无法将具有 @RelatedTo 传出方向的 NodeEntity 与另一个节点一起保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32888056/

相关文章:

java - Spring类路径组件扫描

java - Spring Boot - 不覆盖服务器端口属性

java - 如果代理关闭,则无法创建 Bean

python - 批量插入 neo4j - 最佳选择?

linux - neo4j 服务器在 arch linux 上启动时出错

java - "Expected ' , ' instead of ' ' "Spring Boot POST 方法响应消息

java - Spring Boot 集成流程应用程序在启动时关闭

java - 使用自签名证书(包括中间 CA)部署 Spring Boot 应用程序

java - 在 Spring Boot 应用程序中配置 GCP 凭据的首选方法是什么

java - Spring Data Neo4j (SDN) 查询参数不使用转换器