Reputation: 108
Hey everyone I am fairly new to Neo4j and am having an issue querying my repositories.
Repository is the follow:
public interface NodeOneRepository extends GraphRepository<NodeOne> {
List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);
}
My entities are the following:
@NodeEntity(label = "NodeOne")
public class NodeOne {
@GraphId
private Long id;
private Boolean active = TRUE;
@Relationship(type = "IS_ON")
private NodeTwo nodeTwo;
}
@NodeEntity(label = "NodeTwo")
public class NodeTwo {
@GraphId
private Long id;
@Relationship(type = "CONTAINS", direction = "INCOMING")
private NodeThree nodeThree;
@Relationship(type = "IS_ON", direction = "INCOMING")
private List<NodeOne> nodeOnes = new ArrayList<>();
}
@NodeEntity(label = "NodeThree")
public class NodeThree {
@GraphId
private Long id;
@Relationship(type = "CONTAINS")
private List<NodeTwo> nodeTwos = new ArrayList<>();
}
Getters & Setters omitted. When I call the method I get an empty list. Is there something I am doing incorrectly?
Upvotes: 1
Views: 97
Reputation: 28776
You didn't describe exactly what you wanted to achieve, but I can see two problems:
Problem 1:
The current version of Spring Data Neo4j and OGM only allow nested finders, that is, finders that specify a relationship property, to one depth.
Supported
findByNodeTwoSomePropertyAndActiveTrue(String relatedNodePropertyValue)
Not Supported
findByNodeTwoNodeThree //Nesting relationships in finders is not supported
Problem 2:
Derived Finders Allow Matching Properties and Nested Properties. Not a whole instance of that class.
You can probably achieve what you would like using a custom query.
@Query("custom query here")
List<NodeOne> findByNodeTwoNodeThreeAndActiveTrue(NodeThree nodeThree);
If you need help to write a custom query, you can post another question or join the neo4j-users public slack channel.
Upvotes: 2