3

Running into a problem with the Neo4j OGM library and having a relationship to "subclasses":

@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<>();
    ...
}

Saving a simple graph like this,

enter image description here

and I am unable to get the children back, while the debug log says "More than one class subclasses org.springdot.ogm.eval.entities.MyEntity".

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=[]}

The full example project exhibiting the problem is on Github.

Max Spring
  • 1,111
  • 2
  • 11
  • 18

1 Answers1

3

That debug info just indicates that there were more than one subclass found, but it is not an error condition.

The reason you did not get the entire structure back is because this line of code

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

loads MyRoot with the default loading depth, i.e. 1

This will load MyRoot, set its properties, and it will also load related entities, in this case "container" but not its related entities.

If you increase the load depth (in your case, I set it to 3), you should see the graph fetched as you expect.

Collection<MyRoot> roots = session.loadAll(MyRoot.class,3);
Luanne
  • 19,145
  • 1
  • 39
  • 51