Neo4j OGM与子类的关系

时间:2015-09-02 00:20:43

标签: neo4j neo4j-ogm

遇到Neo4j OGM库的问题并且与#34;子类"有关系:

@NodeEntity class MyEntity{
    @GraphId private Long graphId;
    ...
}

class MyRoot extends MyEntity{
    MyResource resource;
    ...
}

class MyResource extends MyEntity{
    @Relationship(type="HAS_CHILD", direction = Relationship.INCOMING)
    private MyContainer parent;
    ...
}

class MyContainer extends MyResource{
    @Relationship(type="HAS_CHILD", direction = Relationship.OUTGOING)
    private List<MyResource> children = new ArrayList<>();
    ...
}

保存一个这样的简单图表,

enter image description here

我无法让孩子们回来,而调试日志说&#34;多个类子类org.springdot.ogm.eval.entities.MyEntity&#34;。

graph to be saved: r=MyRoot{children=[MyResource{graphId=null, name='.1'}, MyResource{graphId=null, name='.2'}, MyResource{graphId=null, name='.3'}, children=[MyResource{graphId=null, name='.4.1'}, MyResource{graphId=null, name='.4.2'}, MyResource{graphId=null, name='.4.3'}]]}
...
16:52:16.880 [main] DEBUG org.neo4j.ogm.metadata.MetaData - More than one class subclasses org.springdot.ogm.eval.entities.MyEntity
16:52:16.881 [main] DEBUG org.neo4j.ogm.metadata.MetaData - More than one class subclasses org.springdot.ogm.eval.entities.MyEntity
...
graph read back: MyRoot{children=[]}

展示问题的完整示例项目位于Github

1 个答案:

答案 0 :(得分:3)

该调试信息仅表明找到了多个子类,但它不是错误条件。

你没有得到整个结构的原因是因为这行代码

<nav>
    <a href="{{pathFor route='post.new' pw_module='basic-info'}}">Basic info</a>
    <a href="{{pathFor route='post.new' pw_module='itinerary'}}">Itinerary</a>
</nav>

使用default loading depth加载MyRoot,即1

这将加载MyRoot,设置其属性,并且还将加载相关实体,在这种情况下&#34; container&#34;但不是它的相关实体。

如果你增加了加载深度(在你的情况下,我把它设置为3),你应该看到你想象的图形。

Collection<MyRoot> roots = session.loadAll(MyRoot.class);