sdm4n
sdm4n

Reputation: 131

Error mapping node with custom CYPHER RETURN leaving out relations in SDN 7.1.0

Setup

I use an application with Spring Boot 3.1.0 (which brings Spring Data Neo4j 7.1.0) with a Neo4j database 5.8.0. Further, I have a node like this:

@Node
@Data
public class SourceNode {
    @Id
    @GeneratedValue(generatorClass = UUIDStringGenerator.class)
    private String uuid;

    @Relationship(type = "RELATION_NAME", direction = Relationship.Direction.OUTGOING)
    private List<TargetNode> randomRelationName = new ArrayList<>();
}

and a repository with custom CYPHER queries like this:

public interface SourceNodeRepository extends CrudRepository<SourceNode, String> {
    @Query("MATCH (s:SourceNode) RETURN s{.uuid}")
    List<SourceNode> getAllWithoutRelations();

    @Query("MATCH (s:SourceNode) RETURN s{.uuid, __elementId__: toString(id(s))}")
    List<SourceNode> getAllWithoutRelationsFixed();
}

Question

When I execute getAllWithoutRelations() to fetch the source nodes without intentionally mapping the relations, I get:

org.springframework.data.mapping.MappingException: Error mapping Record<{role: {uuid: "xxxxx"}}>
...
Caused by: java.util.NoSuchElementException: No value present

Is it a bug in Spring Data Neo4j 7.1.0 or how can I prevent this problem properly?

When using Spring Boot 3.0.6 bringing Spring Data Neo4j 7.0.5 the query execution works without problems.

Ugly Workaround

I found out, that the problem relates to the source node's internal Neo4j ID, which cannot be determined based on the actual query when executing the custom query. By adding __elementId__: toString(id(s)) (see repository method getAllWithoutRelationsFixed()) to the return object, the problem can be solved, but I doubt that this is a good solution.

Upvotes: 0

Views: 392

Answers (2)

Antony Delgado
Antony Delgado

Reputation: 1

I had similar situation and i've resolve to verify new names of atributes or name attibutes updates. You have there some one nodes with have values with past attributes and it's the problem.

Upvotes: 0

Jennifer Reif
Jennifer Reif

Reputation: 46

I think this relates to this issue with Spring Boot 3.1.0 and Spring Data Neo4j that is waiting for a fix release. You can add the below section of code to the configuration/SpringBootApplication class. It should be fixed once the updated release is published.

@Bean
public Configuration cypherDslConfiguration() {
    return Configuration.newConfig()
        .withDialect(Dialect.NEO4J_5)
        .build();
}

*Update Jun27: The issue is actually due to a problem with the map projection returned in the custom queries. It has been resolved with a fix. More information is available in the Github thread.

Upvotes: 0

Related Questions