问题
I get a timeout while querying for depth 2 using session.load()
.I'm working with Neo4j OGM 1.1.3 (Attempting to migrate from Spring Data Neo4j 3.4). Trying to load a Node object
class Node {
Long id;
String name;
@Relationship(type="NodeToCategory")
Category category;
@Realtionship(type="NodeToChildNode")
Node node
}
class Category {
Long id;
String name;
String color;
Date createdAt;
}
The category that is connected to my node is very popular (20,000 nodes have the same category) and when I use run session.load(Node.class, 1L, 2)
the request times out. Can it be that it is trying to query for all relationships of the category (even though my model Category in Java ignores this relationship)?
what i would expect it to load is simply:
|My Node
| |category
| |child node
| | | category
| | | child node
Which is not a very heavy request and should not timeout (unless it is loading unneeded relationships.
Is there a way to tell a only load certain relationships to deeply?
For example i would like to load 10 levels of a tree but other information on my tree (such as category, role which are not really tree nodes but simply represent more information) I would only want to load them without their relationships. So I would like to load all Node objects and only load other objects along the way without their relationships.
UPDATE
found two open issues that seem to address these problems:
https://github.com/neo4j/neo4j-ogm/issues/55
https://github.com/neo4j/neo4j-ogm/issues/70
回答1:
This issue has been addressed in OGM 3.0 with schema based loading.
Schema based loading means that OGM now looks at your object domain model an only fetches what is really present in your model, instead of everything up to the specified depth.
In your case, as the Category
don't link back to Node
, the new version won't load these many unneeded nodes, leading to a huge performance improvement.
来源:https://stackoverflow.com/questions/33486334/load-an-object-in-neo4j-ogm-1-1-3-ogm-depth-of-2-very-slow