SDN/RX Dynamic Relationships not being populated with custom @Query


We've integrated a Spring Boot Application (v2.3.1) with a Neo4j 4.1.0 instance, using SDN/RX project (spring-data-neo4j-rx-spring-boot-starter v1.1.1). The main feature we leverage on is the Dynamic Relationships.
The insert of Nodes and Dynamic Relationships works fine but the following issues/limitations came up:

A) Dynamic relationships are not being populated when retrieving data with a custom "@Query" (see method graphData() below). I tried the same query in Neo4j Browser and works fine. (They're populated ok though, when creating queries from method names find..By() etc.)

B) Defining dynamic relationships via a Map<String, NodeObj> as explained in the documentation, where the key is the relationship type, there can be only 1 Node linked per type. Is this real? why this limitation? any workaround?

How both issues could be solved?

Below is a sample of the code where we face both issues.

Thanks in advance for your help.

public interface Neo4jNodeRepository extends Neo4jRepository<Neo4jNode, Long> {
    Neo4jNode findByName(String name);
    List<Neo4jNode> findByExternalIdIn(Collection<Long> externalIds);

    @Query("MATCH (s:Neo4jNode)-[r]-(e:Neo4jNode) WHERE s.externalId = $externalId AND e.externalId = $externalId RETURN s,r,e")
    Collection<Neo4jNode> graphData(@Param("externalId") Long externalId);

public class Neo4jNode {
    @Id @GeneratedValue
    private Long id;
    private String name;
    private Long externalId;
    private List<String> labels;

    private Map<String, Neo4jNode> relationships;

    public Neo4jNode() {
        this.labels = new ArrayList<String>();
        this.relationships = new HashMap<String, Neo4jNode>();

    public void addLabel(String label) {
        if(this.labels == null) {
            this.labels = new ArrayList<String>();

    public void relatesTo(String relationType, Neo4jNode node) {
        if (relationships == null) {
            relationships = new HashMap<String, Neo4jNode>();
        relationships.put(relationType, node);

1 Like

I am also waiting for solution to this issue. Dynamic Relationships and Relationships with properties, we can save it to database in all the ways which we can achieve using neo4j desktop. But retrievals are not working as we can achieve using neo4j desktop.

Someone please help us on this. Thanks!

1 Like

You can use a Collection e.g. something like Map<String, List<NodeObj>> for the dynamic relationship to define multiple nodes for the same dynamic relationship type.

A collect(r), collect(e) instead of the scalar return values should do the job, but I have lately also seen an issue around this that might prevent the correct mapping. If there is still a problem, could you raise a ticket for this?

I created a ticket to track the implementation of this functionality

Side note: we will update the documentation on relationship with properties in the near future to reflect the current state. For a glance I answered another question how @RelationshipProperties should get defined now Migration to RX