[英]Why neo4j-ogm not saves relations to embedded neo4j-database?
我尝试获得带有spring-boot,joinfaces和带有object-mapping ogm的嵌入式neo4j -graph-database的嵌入式tomcat服务器的工作系统。 一切似乎都正常。 我将来源提交到https://svn.riouxsvn.com/circlead-embedd/circlead-embedded/
问题在于所有neo4j-ogm示例 (请参见http://www.hascode.com/2016/07/object-graph-mapping-by-example-with-neo4j-ogm-and-java/ )都显示@Relationship与ogm一起使用。 但是当我用
@NodeEntity
public abstract class GenericNode<T> implements INode<T> {
@GraphId
public Long id;
@SuppressWarnings("unused")
private void setId(Long id) {
this.id = id;
}
public String label;
@Relationship(type = "PARENT_OF", direction = Relationship.INCOMING)
public Set<T> parents = new HashSet<T>();
@Relationship(type = "CHILD_OF", direction = Relationship.OUTGOING)
public Set<T> children = new HashSet<T>();
...
那么所有的关系似乎都不会写在数据库中,因为这些行
Role rp = new Role("Role 1");
Role rc = new Role("Role 2");
rc.addParent(rp);
session.save(rc);
Iterable<Role> roles = session.query(Role.class, "MATCH (x) RETURN x;", Collections.<String, Object>emptyMap());
for (Role role : roles) {
System.out.println(role);
}
在控制台中显示数据库关系丢失。 似乎只有在活动的会话关系中才能找到。 服务器重新引导后,所有关系都将丢失。
Role [id=52, label=Role 2, parents=[]]
Role [id=53, label=Role 1, parents=[]]
Role [id=54, label=Role 1, parents=[]]
Role [id=55, label=Role 2, parents=[54]]
我不知道发生这种错误是什么。 我使用neo4j-ogm 2.1.2和neo4j 3.1.3。
任何想法?
您所看到的结果是预期的-neo4j-ogm映射您在密码查询中返回的内容(以及您在会话中已经拥有的内容)。 如果还需要相关实体,则返回关系和其他节点:
MATCH (x)-[r]-(x2) RETURN x,r,x2
或者,例如,如果您只想将父字段水合:
MATCH (x)<-[r:PARENT_OF]-(p) RETURN x,r,p
这只会水合第一级。 要混合所有级别(父级的父级),您需要使用可变长度路径并返回其节点和关系(直接返回路径无法可靠地工作):
MATCH p=(x)-[:PARENT_OF*..]-() RETURN nodes(p),rels(p)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.