2
votes

I try to load an entire object (with its hierarchy) with this code:

final Filter filter = new Filter (this.identity.name(),ComparisonOperator.EQUALS, identity);
filter.setRelationshipDirection(Relationship.OUTGOING);     
final Filters filters = new Filters (filter);
final Collection<T> values = ogmSession.loadAll(this.classType,filters , -1);
if (values != null){
    rvalue = values.iterator().next();
}

But the generated query is (with performance issue):

BoltRequest - Request: MATCH (n:`Procedure`) WHERE n.`name` = { `name_0` }  WITH n MATCH p=(n)-[*0..]-(m) RETURN p, ID(n) with params {name_0=WMS-1-B}  

Instead of something like that (with relationship direction in last MATCH clause):

MATCH (n:`Procedure`) WHERE n.`name` = { `name_0` }  WITH n MATCH p=(n)-[*0..]->(m) RETURN p, ID(n) with params {name_0=WMS-1-B}  

Did I miss something or is it a bug ? Thanks.

Querying Neo4j 3.2 CE with the following dependencies:

<parent>
    <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
</parent>
<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>1.3.1</version>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-core</artifactId>         
       <version>2.1.3</version>         
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-bolt-driver</artifactId>
    <version>2.1.3</version>            
</dependency>
2
Have you relationships in both directions? That is: (n)-->(m) and (n)<--(m). - Bruno Peres
Yes, I have something like that : (:Procedure)-[:ROUTE_TO]->(:Task)-->(:Sink)<--(:Task) and (:Procedure)<-[:IS_PART_OF]-(:Task) - SylvainRoussy

2 Answers

1
votes

The Filter API is not very clear on this.

The setRelationshipDirection (and setRelationshipType) relates to the filter MATCH on nested properties. The last MATCH will always be p=(n)-[*0..]-(m) to load all related nodes (but also see this feature request).

It is also set automatically based on the domain model. For example:

Filter filter = new Filter("itemName", "item1");
filter.setNestedPropertyName("items");
filter.setNestedPropertyType(Item.class);
session.loadAll(User.class, filter);

would result into

MATCH (n:`User`) MATCH (m0:`Item`) 
WHERE m0.`itemName` = { `items_itemName_0` } 
MATCH (n)-[:`HAS_ITEM`]-(m0) 
WITH n 
MATCH p=(n)-[*0..1]-(m) // provide depth to change 1 to something else
RETURN ....

The current API is there to support derived finders in Spring Data Neo4j and it might be easier and more readable to use custom query (which also allows you to directly specify what to return and map - see Partially hydrating entities).

0
votes

Ok, solved with queryForObject method, for example:

T rvalue = ogmSession.queryForObject(this.classType, 
  "MATCH (n:`Procedure`) WHERE n.`name` = { `procedureName` } "+ 
  "WITH n MATCH p=(n)-[*0..10]->(m) RETURN p, ID(n)", Values.parameters("procedureName",identity).asMap());

Thanks to all.