Skip to content

Count() aggregator NoRootNodeMappingException #2633

@goldman7911

Description

@goldman7911

Hi all,

I have created a replicable repo for this issue: https://github.com/goldman7911/spring-data-understanding
It will need a clear Neo4j running and run tests to validate what I'll try to explain here.

I'm starting feeling there is something wrong or my understanding is complety wrong for OGM

My data is:

{
  "identity": 171,
  "labels": [
    "RootMarker"
  ],
  "properties": {
"lastModifiedDate": 1666934940115,
"p5Latest": true,
"messageIds": [
      "fake-900b-49ac-92c7-fake",
      "fake-7777-4ab1-7777-fake"
    ],
"resources": 1,
"messageId": "fake-7777-4ab1-7777-fake",
"deviceId": "XXXXX",
"domainId": "fake-7777-4ab1-7777-fake",
"createdDate": 1666896513598,
"drniId": 222222222,
"id": 11,
"isFull": true,
"resyncId": "fake-7777-4ab1-7777-fake",
"status": "resync",
"latest": [
      22
    ]
  }
}

My objective is to map this Query to Java:

image

As you can see, all methods getResyncIdAndMessageIdsCountPureSDNXXXX are failing with same error

image

org.springframework.data.neo4j.core.mapping.NoRootNodeMappingException: Could not find mappable nodes or relationships inside Record<{resyncId: "fake-7777-4ab1-7777-fake", counter: 2}> for org.springframework.data.neo4j.core.mapping.DefaultNeo4jPersistentEntity@777d191f

Is weird how the same Neo4jRepository uses neo4jClient behind the scenes but could not map it. This method bellow I could sucessfully use in MyService.java

public Collection<MyDTO> getResyncIdandMessageIdsCount() throws NoSuchElementException {
        Collection<MyDTO> result = neo4jClient.query("match (r:RootMarker) UNWIND r.messageIds as rx return r.resyncId as resyncId, count(rx) as counter")
                .fetchAs(MyDTO.class)
                .mappedBy((typeSystem, record) -> {
                    String resyncId = record.get("resyncId").asString();
                    Long counter = record.get("counter").asLong();
                    return new MyDTO(resyncId, counter);
                }).all();
        return result;
    }

Also, just the first two of MyRepository do work. The 3 left receive the same error NoRootNodeMappingException.

public interface MyRepository extends Neo4jRepository<RootMarker, Long> {

    @Query("MATCH (n:RootMarker) RETURN n ORDER BY n.domainId")
    List<RootMarker> getRootMarker();

    @Query("MATCH (n:RootMarker) RETURN count(n)")
    Long countRootMarker();

    //THAT'S NOT WORKING
    @Query("match (r:RootMarker) UNWIND r.messageIds as rx return r.resyncId as resyncId, count(rx) as counter")
    Collection<MyDTO> getResyncIdAndMessageIdsCountPureSDN();

    //THAT'S NOT WORKING
    @Query("match (r:RootMarker) UNWIND r.messageIds as rx return r.resyncId as resyncId, count(rx) as counter")
    <T> Collection<T> getResyncIdAndMessageIdsCountPureSDNGenerics(Class<T> type);

    //THAT'S NOT WORKING
    @Query("match (r:RootMarker) UNWIND r.messageIds as rx return r.resyncId as resyncId, count(rx) as counter")
    Collection<MyProjectionDTO> getResyncIdAndMessageIdsCountPureSDNProjections();

}

Please help me understand why I can't map count aggregator result as Long by using OGM

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions