【发布时间】:2017-05-17 20:39:31
【问题描述】:
我试图获得一个带有 spring-boot、joinfaces 和嵌入式 neo4j-graph-database 和对象映射 ogm 的嵌入式 tomcat 服务器的工作系统。一切似乎都很好。我将我的消息来源提交给https://svn.riouxsvn.com/circlead-embedd/circlead-embedded/
问题是所有neo4j-ogm-examples(参见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。
有什么想法吗?
【问题讨论】:
-
另请注意,您将在父母和孩子之间有 2 种关系 -
PARENT_OF和CHILD_OF- 这通常是一个建模错误,1 个关系就足够了。关系的方向应该告诉你语义——什么是父母,什么是孩子。
标签: java spring-boot neo4j neo4j-ogm