Skip to content

Fail to use map of nodes as custom query param #2791

@rogelio-o

Description

@rogelio-o

We are saving a large list of nodes in Neo4j with many edges. Instead of defining the relationship as part of the node, we are saving all the nodes first and then all the edges with the Cypher query below. This reduces the number of calls to DB to 2 and improves the performance.

@Query("""
        UNWIND keys($relationships) as sourceId
        UNWIND $relationships[sourceId] as relationship
        MATCH
          (source:`package` {id: sourceId}),
          (target:`package` {id: relationship.__target__.__id__})
        MERGE (source)-[r:DEPENDS_ON]->(target)
        SET r += relationship.__properties__
      """)
  Mono<Void> mergeRelationships(@Param("relationships") Map<String, List<PackageRelationshipProperties>> relationships);

However, it does not work because entities are converted only when they are in a list, not in a map (and, of course, not in a map of lists). This happens here.

A perfect solution would be to reduce the number of queries to 2 in the saveAll method. However, if this is not possible, supporting the conversion of entities recursively will solve the problem.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions