SDN6 return the relationship

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

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:

  1. You should really name your relationship, otherwise SDN will search for relationships named RELATIONSHIP (derived from the properties name).
  2. (naming) It might be due to a migration from SDN 5 but the @TargetNode in the @RelationshipProperties is really the target of the relationship in the sense of: 'The Resource's relationship counterpart is the @TargetNode'.