Using DynamicLabels in Neo4jRepository SaveAll

Hi there,

I am trying to insert/update nodes with Neo4jNodeRepository SaveAll function and add labels with the @DynamicLabels annotation. All nodes are inserted into the database but without the labels.
When I use the Save function the dynamic Labels are added to the nodes.

When I look in de implementation of the SaveAll function in Neo4jTemplate.java, there seems to be no implementation for Dynamic labels. In de Save (saveImpl) there is a call to determineDynamicLabels. Is this by design? Is it possible to add dynamic labels to the saveAll function as well?

Thanks in advance,

Fedor

Thanks for pointing me to this. You are right, it was "just missing". I targeted it with this issue Dynamic labels won't get persisted on saveAll. · Issue #2110 · spring-projects/spring-data-neo4j · GitHub and it will get included in the service release that will get published later today.

1 Like

Thanks Gerrit for your quick response. I'm glad we can use de save all with dynamic labels!

Is there a big penalty in using save all with dynamic labels? Internally it seems to be calling the normal save, would it be better for a large import to save labels of the same type in one go, without the use of dynamic labels, in terms of performance?

The save/update for dynamic labels has to happen in a call for each provided entity. Otherwise we cannot set and remove the labels on a per node base. At the moment the old labels get loaded from the database directly prior the actual (single) save call to create the correct label patch (REMOVE / SET) part for the save statement.

Hi @gerrit.meier . I'm using dynamic labels and running into a major ReactiveNeo4jRepository.save performance issue that I believe relates to the below query, generated by the Spring Data Neo4j package.

MATCH (n) WHERE n.id = $__id__ UNWIND labels(n) AS label WITH label WHERE NOT (label IN $__staticLabels__) RETURN collect(label) AS __nodeLabels__

From my testing this will cause a full node scan, as it can't leverage a schema index if it's not using a label in the match statement. Am I correct in that and is there a way to avoid it?

I'm using spring boot v 2.4.4 and spring-data-neo4j v 6.0.6