我正在使用Spring Boot
和Neo4J 2.1.8
,并创建了两个NodeEntities
父和子。
父类是
@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;
}
parentRepo
和childRepo
类都扩展了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)
答案 0 :(得分:3)
好的我明白了。我没有打电话给parentRepo.save(parent)
我做的是
childRepo.save(child);
Parent parent=parentRepo.retriveParent(id);
parent.getChildren().add(child);
节点和关系已自动更新。无需明确调用parentRepo.save()