Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-19-2022 06:07 PM
I want to query all the relationship satisfied some condition. And here's the node,
@Data
@Node
public class Resource {
@Id
@GeneratedValue
private Long id;
@Property("name")
private String name;
private String code;
@Property("parent_code")
private String parentCode;
private String label;
// @Relationship
// private List<Neo4jRelationship> relationship = new ArrayList<>();
}
Here's the relationship
@Data
@RelationshipProperties
public class Neo4jRelationship {
@RelationshipId
private Long id;
@TargetNode
private Resource startNode;
}
Here's the cypher:
@Query("match p = (a : category_first {name: $name})-[*1..2]-() return p")
List<Neo4jRelationship> getFistCatNode(@Param("name") String name);
which returns an empty list, And if I change the return type to Object, like:
@Query("match p = (a : category_first {name: $name})-[*1..2]-() return p")
List<Object> getFistCatNode(@Param("name") String name);
The cypher can return normally, but I can't get the internal field.
What should I do. Any help will be grateful
03-20-2022 11:52 PM
SDN does not handle RelationshipProperties as entities. You have to fetch the matching Resource
with their relationships.
@Query("match p = (a : category_first {name: $name})-[*1..2]-() return a, collect(nodes(p)), collect(relationships(p))")
List<Resource> getFistCatNode(@Param("name") String name);
The resulting relationships will then be reachable:
List<Resource> resources = getFistCatNode("foo");
for (Resource resource: resources) {
for (Neo4jRelationship relationship: resource.relationship) {
// also loop then over the relationships of the TargetNodes
}
}
But two things that came up while looking at your example:
RELATIONSHIP
(derived from the properties name).@TargetNode
in the @RelationshipProperties
is really the target of the relationship in the sense of: 'The Resource
's relationship counterpart is the @TargetNode
'.All the sessions of the conference are now available online